By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Context Menu on ListView

P: n/a
Hi there,
I fear the answer to this question is going to be very simple but it's me
running around in circles at the moment.

I wish to pop up a context menu on my ListView if and only if I right click
over a selected item.

What I mean by this is that say my list view can hold 10 items but i've only
3 items presently, if i click on the space where there is no ListView item
then i do not wish to show my context menu.

Anyone got any ideas on this?

thanks in advance
Brian
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

ok figured it out

private void OnEventListView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ListViewHitTestInfo hitTestInfo = HitTest(e.X, e.Y);
if (hitTestInfo.Item != null)
{
//show the context menu strip
cmsOptions.Show(this, e.X, e.Y);
}
}
}

"Brian Keating" wrote:
Hi there,
I fear the answer to this question is going to be very simple but it's me
running around in circles at the moment.

I wish to pop up a context menu on my ListView if and only if I right click
over a selected item.

What I mean by this is that say my list view can hold 10 items but i've only
3 items presently, if i click on the space where there is no ListView item
then i do not wish to show my context menu.

Anyone got any ideas on this?

thanks in advance
Brian

Nov 17 '05 #2

P: n/a
Umm... There's also a ContextMenu_Popup event. You might want to think
about doing it there.

Tom P.
"Brian Keating" <csharp at briankeating.net> wrote in message
news:11**********************************@microsof t.com...

ok figured it out

private void OnEventListView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ListViewHitTestInfo hitTestInfo = HitTest(e.X, e.Y);
if (hitTestInfo.Item != null)
{
//show the context menu strip
cmsOptions.Show(this, e.X, e.Y);
}
}
}

"Brian Keating" wrote:
Hi there,
I fear the answer to this question is going to be very simple but it's me
running around in circles at the moment.

I wish to pop up a context menu on my ListView if and only if I right
click
over a selected item.

What I mean by this is that say my list view can hold 10 items but i've
only
3 items presently, if i click on the space where there is no ListView
item
then i do not wish to show my context menu.

Anyone got any ideas on this?

thanks in advance
Brian

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.