Context Menu on ListView

G

Guest

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
 
G

Guest

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);
}
}
}
 
H

Henry Padilla

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

Tom P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top