Handle click on a sub-item of ListView

后端 未结 3 1206
孤街浪徒
孤街浪徒 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:18

    You can use the ListView.MouseClick event as follows:

    private void listView_MouseClick(object sender, MouseEventArgs e)
    {
        // Hittestinfo of the clicked ListView location
        ListViewHitTestInfo listViewHitTestInfo = listView.HitTest(e.X, e.Y);
    
        // Index of the clicked ListView column
        int columnIndex = listViewHitTestInfo.Item.SubItems.IndexOf(listViewHitTestInfo.SubItem);
    
        ...
    }
    

提交回复
热议问题