Find the selected list item

I currently have a list that has multiple rows of data and I have a contextmenustrip in C # .NET.

I am having problems that when you click on a menu item, I want to know which row was selected.

+1


source to share


3 answers


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

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

      



lvFiles is a ListView.

+2


source


To get the selected list item try this:

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



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

+1


source


I really don't know what you mean here. Could you please explain your problem further or provide some sample code?

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

0


source







All Articles