c# - ListView 中选定索引的问题

标签 c# winforms listview arraylist

我有一个数组列表,其中包含我自己的类的对象。我想从 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/

相关文章:

c# - Asp.Net 在 json 中返回自定义对象

c# - slider 值在更改最小值和最大值后不更新

c# - 在 .NET 的 Win Form 中嵌入不同的应用程序

c# - C# WinformsErrorProvider

Android ListView 过度滚动问题

android - 如何在android中创建包含超过100个图像和文本的listview?

c# - 使用 SMO 更改 DataFile MaxSize

c# - C# 任务和全局变量

.net - WinForms 到 WPF - 我们如何从这里到达那里?

android 如何将 hashset 放入适配器中以在 listview 中使用