List View Context Menu

  • Thread starter Thread starter rajkiranpro
  • Start date Start date
R

rajkiranpro

I have created a context menu for the listview and I wanno show the context
menu if and only if a particular listviewitem is highlighted.

I used the following code

private void contextLstContent_Opening(object sender,
CancelEventArgs e)
{
if (lstContent.SelectedItems.Count < 1)
{
e.Cancel = true;
}
}

instead of doing like this want is I want to select/highlight the
listviewitem pointed by the mouse pointer when right clicked and show the
context menu.

any suggestions???

Regards
Rajkiran
 
Hi

You can use ctlListView1_MouseDown:

if (this.ctlListView1.GetItemAt(e.X, e.Y) != null)
{
this.ctlListView1.GetItemAt(e.X, e.Y).Selected = true;

// Here you can decide what ContextMenu to display ...

}


Regards
Frank Uray
 
You can use ctlListView1_MouseDown:

if (this.ctlListView1.GetItemAt(e.X, e.Y) != null)
{
this.ctlListView1.GetItemAt(e.X, e.Y).Selected = true;

// Here you can decide what ContextMenu to display ...

}

Hopefully you're only DECIDING on what menu to display and not actually
displaying it. You should only display context menus on mouse UP, not down.
And because of that I'd recommend you do ALL the processing in MouseUp.
 
Back
Top