问题
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