编程语言
首页 > 编程语言> > c# – 在ListView中选择下一项

c# – 在ListView中选择下一项

作者:互联网

我有一个方法删除ListView中当前选定的项目

listView1.Items.Remove(listView1.SelectedItems[0]);

删除选定的ListView后,如何在ListView中选择下一个?

我试过类似的东西

var index = listView1.SelectedItems[0].Index;
listView1.Items.Remove(listView1.SelectedItems[0]);
listView1.SelectedItems[0].Index = index;

但是我得到了错误

Property or indexer 'System.Windows.Forms.ListViewItem.Index' cannot be 
assigned to -- it is read only

谢谢.

解决方法:

ListView没有SelectedIndex属性.它有一个SelectedIndices的财产.

Gets the indexes of the selected items in the control.

ListView.SelectedIndexCollection indexes = this.ListView1.SelectedIndices;

foreach ( int i in indexes )
{
 //
}

标签:c,winforms,listview,selectedindex
来源: https://codeday.me/bug/20190703/1370775.html