ListView Item select in winform
27,290
Solution 1
Just handle the Click
event on the list and use the ListView.SelectedItems
property to get what items are selected:
private void listView1_Click(object sender, EventArgs e)
{
var firstSelectedItem = listView1.SelectedItems[0];
}
Solution 2
u can use MouseEventArgs and get the mouse location check if it exists inside the selected item bound , that means the click was made on the selected item .
EDIT : example :
private void myList_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (myList.SelectedItems.Count >= 1)
{
ListViewItem item = myList.SelectedItems[0];
//here i check for the Mouse pointer location on click if its contained
// in the actual selected item's bounds or not .
// cuz i ran into a problem with the ui once because of that ..
if (item.Bounds.Contains(e.Location))
{
MessageBox.Show("Double Clicked on :"+item.Text);
}
}
}
Author by
Admin
Updated on July 22, 2022Comments
-
Admin almost 2 years
I want to select item in a ListView upon clicking. I also want to know what I clicked. I work on winforms with c#.I also want to know How I can clicking the all row?
-
Totty.js about 11 yearsif I click twice on the same item it will dispatch the event twice when it should not because the selection didn't changed.