Question

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.

Was it helpful?

Solution

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

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

lvFiles is the ListView.

OTHER TIPS

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

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top