确定ListView中单击的列 [英] Determine clicked column in ListView
本文介绍了确定ListView中单击的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要列在C#
我从的如何确定在ListView 点击的列索引,但我不知道我应该怎么实现它。
I have some sample code from How to determine the clicked column index in a Listview but I'm not sure how I should implement it.
推荐答案
哎呀,大家都懒得张贴code。有三个步骤的流程:
Jeez, everyone's too lazy to post code. There are three steps to the process:
- 使用获得鼠标位置
Control.MousePosition
并转换为客户区坐标。 - 调用
的HitTest
函数查找鼠标指向。此方法返回大量信息的对象,除了实际的列数等等... - 使用
的IndexOf
找到列号。 搜索子项目阵列
- Get the mouse position using
Control.MousePosition
and convert to client coordinates. - Call the
HitTest
function to find what the mouse is pointing to. This returns an object with lots of information except the actual column number so... - Search the subitems array using
IndexOf
to find the column number.
这里的code:
private void listViewMasterVolt_DoubleClick(object sender, EventArgs e)
{
Point mousePosition = myListView.PointToClient(Control.MousePosition);
ListViewHitTestInfo hit = myListView.HitTest(mousePosition);
int columnindex = hit.Item.SubItems.IndexOf(hit.SubItem);
}
这篇关于确定ListView中单击的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文