Show right click options in the selected list Record only - Winforms C # .NET

alt text http://img413.imageshack.us/img413/9417/snapshotapp.jpg

ContextMenuStrip is bound to a ListView control. However, right-clicking (change) appears when I click on the ListView area, it gives me an exceptional error, because the editing implementation can only handle the selected row. I want it to appear only in the selected row (blue highlighted row). How can i do this?

+3
source share
1 answer

The Reset ContextMenuStrip property returns to (none). Add a MouseUp event handler and use ListView.HitTest () to find out where it was clicked. For instance:

    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);
        }
    }
+9
source

Source: https://habr.com/ru/post/1746988/


All Articles