views:

12

answers:

1

alt text

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?

+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
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
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
Worked! It was my mistake, i choose MouseUp on the wrong control...Thanks!
peace