我有一个方法删除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 )
{
//
}