Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select row from winforms listview

Tags:

c#

.net

winforms

I have listview which is populated with list of data. Now I want to select desired row and on click button to recognize that item to delete from a collection.

Question is how to recognize selected row from the listview?

private void buttonDelete_Click(object sender, EventArgs e)
{
    //selected data is of custom type MyData
    var selected = (MyData)....?
}

Thanks

like image 933
panjo Avatar asked Jan 19 '26 11:01

panjo


1 Answers

This should works

  private void buttonDelete_Click(object sender, EventArgs e)
    {
        //selected data is of custom type MyData
        var selected = yourListView.SelectedItems.First();
    }
like image 93
provençal le breton Avatar answered Jan 22 '26 03:01

provençal le breton