Finding the selected item of list view

前提是你 提交于 2019-12-11 05:46:02

问题


I currently have a list view which has several rows of data and I have a contextmenustrip in C# .NET.

What I am having problems with is when you click on the menu strip item I want to know which row has been selected.


回答1:


To get selected rows as sindre says you do like this:

foreach (ListViewItem item in lvFiles.SelectedItems)
{
....................................
}

lvFiles is the ListView.




回答2:


To get the selected item of list view, try this:

int index = 0;
if (this.myListView.SelectedItem.Count > 0)
index = this.myListView.SelectedIndices[0]

This will give you the index of selected item in listview.
You may also refer this:
http://www.neowin.net/forum/index.php?showtopic=358458




回答3:


I really don't know what you mean here. Can you please explain your problem further or provide a code example?

To get the selected row in a ListView you use the ListView.SelectedItems property. ListView.SelectedItems[0] will give you the first seleted item (as there can be more than one item selected)



来源:https://stackoverflow.com/questions/325241/finding-the-selected-item-of-list-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!