List View Context Menu

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
 
F

Frank Uray

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
 
J

Jeff Johnson

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.
 

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