Context Menu on ListView

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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);
}
}
}
 
Umm... There's also a ContextMenu_Popup event. You might want to think
about doing it there.

Tom P.
 
Back
Top