我正在尝试从 ListView 组件 (C# .NET 4.0) 中的 ListViewGroup 中删除所有项目。我尝试了以下事情,但它们返回了意想不到的行为。
listView1.Groups[4].Items.Clear(); // Does only remove the item from the group,
// but is then placed in a new Default group.
foreach (ListViewItem item in listView1.Groups[4].Items)
{
item.Remove();
}
// This throws an error which says that the list is changed.
我现在listView1.Items.Clear();
用来清除组内的所有项目,并一一阅读。但是,这会导致我的 GUI 在执行此操作时闪烁。我想知道如何删除组中的所有项目。所以我只需要重新添加项目组(我想要的,因为项目的数量不同,名称和子项目也不同)。
注意:该组被调用lvgChannels
并具有索引 4。