Handle click on a sub-item of ListView

后端 未结 3 1204
孤街浪徒
孤街浪徒 2020-12-16 12:44

How can I handle click on a sub-item of ListView (detail mode)? i.e. I need to detect what exactly column was clicked.

3条回答
  •  被撕碎了的回忆
    2020-12-16 13:29

    You need to determine the column by its position:

    private void listView_Click(object sender, EventArgs e)
    {
        Point mousePos = listView.PointToClient(Control.MousePosition);
        ListViewHitTestInfo hitTest = listView.HitTest(mousePos);
        int columnIndex = hitTest.Item.SubItems.IndexOf(hitTest.SubItem);
    }
    

提交回复
热议问题