Problems with selected indices in listview

前端 未结 3 870
天涯浪人
天涯浪人 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:07

    The error is because listView1.SelectedIndices is empty, do you have a row selected?

    you probable want to wrap in a test

    ListView.SelectedIndexCollection selected=listView1.SelectedIndicies;
    
    if (selected.Count==0) {
     // code for no items selected
    } else {
      TrackInformation t=(TrackInformation) SongList[selected[0]]; 
      // rest of code to deal with t
    }
    

提交回复
热议问题