开发者

Show Right Click Options on the Selected List View Record Only - Winforms C#.NET

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

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 e开发者_运维知识库xceptional 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?


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);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜