views:

4123

answers:

4

Hey,

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.

Any help gratly appreciated.

A: 

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)

sindre j
A: 

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

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

lvFiles is the ListView.

netadictos
A: 

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

Sachin Gaur
A: 

Thanks for your help, netadictos answer was perfect :)

cheers.

instigator