Problems with selected indices in listview

前端 未结 3 861
天涯浪人
天涯浪人 2021-01-15 18:21

I have an arraylist which contain objects of my own class. I want to fetch the object from the array list which has the index = selectedindex of listview.

I tried th

3条回答
  •  有刺的猬
    2021-01-15 19:02

    The ListView.SelectedIndexChanged event has a quirk that bombs your code. When you start your program, no item is selected. Click an item and SelectedIndexChanged fires, no problem. Now click another item and the event fires twice. First to let you know, unhelpfully, that the first item is unselected. Then again to tell you that the new item is selected. That first event is going to make you index an empty array, kaboom. RV1987's snippet prevents this.

提交回复
热议问题