开发者

How can I access the index of the column in the ListView that I clicked?

I have a开发者_开发技巧 ListView with several columns. How can I access the index of the column in the ListView when its clicked?


In the function that handles the click event, there are two arguments, sender and e. e is the event arguments. The members of e in any event-handling function will be objects having to do with the event that you are handling.

Therefore, look at the Intellisense for e to find data about which column you just clicked.


You can use the MouseEventArgs parameter to get the mouse position then feed that into HitTest() to get detailed information such as the actual row and column that were clicked. Here's the code:

private void myListView_MouseClick(object sender, MouseEventArgs e)
{
    ListViewHitTestInfo hitItem = myListView.HitTest(e.Location);

    // hitItem now contains the item, subitem, row index and so on.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜