Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get ListView Item to respond to Click

Status
Not open for further replies.

MeonR

Programmer
Aug 16, 2002
97
US
Hi All:

Ok I Have a Winforms Listview control with several items in it
I want to be able to click on an item and trigger code, sounds
simple enough so I try using a switch in the ListView click event

ListViewItem lItem = new ListViewItem();
int i = lItem.Index;
switch(ListView.SelectedItems.Index)
{
case 0:
//Do something
break;
case 1:
//Do something else
break;
}
This does nothing. There does'nt seem to be a way to reference individual list items using the ListView object
How do I correct this?

TIA
MeonR
 
Hi chmohan:

Thaks for the assist, got it working looks like the thing that threw me was SelectedItems[0]; Anyway now it works the
Thanks Again.

The Code
//In ItemActivate
{
ListViewItem item = lvLaunch.SelectedItems[0];
switch(item.Index)
{
case 0:
//Do Something
break;
case 1:
// Do Something Else
break;
case 2:
//etc....
break;
}

}

MeonR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top