El TecnoBaúl de Kiquenet

Kiquenet boring stories

Posts Tagged ‘listview’

WinForms. ListView. SelectedItem

Posted by kiquenet en 23 diciembre 2014

Using SelectedItems:

if (listView1.SelectedItems.Count > 0)
{
     var item = listView1.SelectedItems[0];
    var text = listView1.SelectedItems[0].Text;
    // listView1.SelectedItems[0].SubItems[0].Text

     //rest of your logic
}

Using SelectedIndices:

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
     if (listView1.SelectedIndices.Count <= 0) { return; }
     int intselectedindex = listView1.SelectedIndices[0];
     if (intselectedindex >= 0)
     {
          String text = listView1.Items[intselectedindex].Text;
          //do something
     //MessageBox.Show(listView1.Items[intselectedindex].Text);
     }
}

Sources:
http://stackoverflow.com/questions/15091400/get-single-listview-selecteditem

Anuncios

Posted in .NET | Etiquetado: , | Leave a Comment »