[英]In my ListView control, is there a way for me to GET the index of a clicked item?
Pretty straight forward question, but I can't find a way to do it. 非常简单的问题,但我找不到解决方法。
When a user double clicks an item in my ListView I want to save the index number of the clicked item. 当用户双击我的ListView中的项目时,我想保存所单击项目的索引号。
Assuming that you have a reference to the ListViewItem: 假设您对ListViewItem有引用:
listView.Items.IndexOf(listViewItem)
Or just access listView.SelectedIndices
in the Activate event handler -- if your ListView is single-select then there'll be only one index in there. 或者只访问Activate事件处理程序中的listView.SelectedIndices
-如果您的ListView是单选的,则那里将只有一个索引。
It depends on which ListView you're using. 这取决于您所使用的ListView 。 All three have a property to get the selected item's index: 这三个都具有获取所选项目的索引的属性:
For Windows Forms, use ListView.SelectedIndices 对于Windows窗体,请使用ListView.SelectedIndices
For WPF, use ListView.SelectedIndex 对于WPF,请使用ListView.SelectedIndex
For Web, use ListView.SelectedIndex 对于Web,请使用ListView.SelectedIndex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.