【发布时间】:2013-06-21 09:01:00
【问题描述】:
我正在尝试从 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。
【问题讨论】: