The ContextMenuStrip tied to the ListView control. However, the right click option (edit) appear where ever i click on the ListView area, this gives me exceptional error because the implementation of edit can only cope with a selected row. I only want it to appear when on a selected row (blue highlighted row). How can i do it?
views:
12answers:
1
+1
A:
Reset the ContextMenuStrip property back to (none). Implement the MouseUp event handler and use ListView.HitTest() to find out where it was clicked. For example:
private void listView1_MouseUp(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
var loc = listView1.HitTest(e.Location);
if (loc.Item != null) contextMenuStrip1.Show(listView1, e.Location);
}
}
Hans Passant
2010-05-25 10:30:47
Just to let you know, it didn't work, when i right click i don't get the right click option (edit). I wonder why. I'm trying to figure it out, once i get it will let you know. Any more suggestions will be appreciated
peace
2010-05-25 11:23:54
Hmm, there's no failure mode there, other than not setting the MouseUp event properly. Use the lightning bolt icon in the Properties window.
Hans Passant
2010-05-25 11:26:56
Worked! It was my mistake, i choose MouseUp on the wrong control...Thanks!
peace
2010-05-25 11:52:25