Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView Item select in winform

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?

like image 287
mnaftal Avatar asked May 19 '11 11:05

mnaftal


2 Answers

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);
            }
        }
    }
like image 175
0 x 5 4 4 D Avatar answered Oct 23 '22 13:10

0 x 5 4 4 D


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];
}
like image 39
Teoman Soygul Avatar answered Oct 23 '22 14:10

Teoman Soygul