我有一个数组列表,其中包含我自己的类的对象。我想从 ListView 的 index = selectedindex 的数组列表中获取对象。
我试过这个:
TrackInformation t=(TrackInformation) SongList[listView1.SelectedIndices[0]];
TrackInformation
是我的类,SongList
是类型为 TrackInformation
的 ArrayList。
listview1 不允许选择多个索引,所以我想要 SelectedIndices
集合的第一个元素。
我收到 ArgumentOutOfRangeException
,它说“0”的值对“index”无效。
最佳答案
将此行放在您的代码之前 -
if(listView1.SelectedIndices.Count > 0)
{
TrackInformation t=(TrackInformation) SongList[listView1.SelectedIndices[0]];
}
关于c# - ListView 中选定索引的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11922872/