ListView control ?

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

How can you
1.) Get the text of an item selected?
2.) Get the index number of the item selected?
3.) Tell if the user clicked in a blank area
 
1.
if(listView1.SelectedItems.Count > 0)
{
//get the text of the first selected item
string str = listView1.SelectedItems[0].Text ;
}

2.
if(listView1.SelectedItems.Count > 0)
{
//get the text of the first selected item
int index = listView1.SelectedIndices[0];
}

3. You have to process in mouse down or mouseup event

private void listView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
ListViewItem item = listView1.GetItemAt(e.X,e.Y);
if(item == null)
{
//user has clicked blanked area
}
}
 
Back
Top