SelectedIndices in ListView

A

Alberto

In the event SelectedIndexChanged of a listView I wrote this code:
this.Text = lst.SelectedIndices[0].ToString();

The ListView has the MultiSelect property set to false.
The first time the event is called it works fine but in the second call, it
breaks.

does anybody why?
Thank you very much
 
C

Cor Ligthert

Alberto,

I don't know if this is the best method, however it goes.

(Assuming you use it in the index changed event, it is fired when you
deselect you know)

if (lst.SelectedIndices.Count != 0)
{
this.Text = lst.SelectedItems[0].ToString();
}

I hope this helps

Merry Christmas

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top