我想在列表视图(winform)中对我的项目进行分组,组标题显示组中的项目数(包括 0 个项目)。我的问题是,当我从组或列表视图中清除项目时,组标题会消失。
如何确保组标题不会消失?我看不到要在 ListView 或 ListViewGroup 类中设置的任何属性。
谢谢
考虑代码:
ListViewGroup groupA;
ListViewGroup groupB;
private void button1_Click(object sender, EventArgs e)
{
//Create group A and B and add them to the groups collection
groupA = new ListViewGroup("A");
listView1.Groups.Add(groupA);
groupB = new ListViewGroup("B");
listView1.Groups.Add(groupB);
//Add 2 items in the list view and update the group headers
listView1.Items.Add(new ListViewItem("Item1", groupA));
groupA.Header = "A - 1 item";
listView1.Items.Add(new ListViewItem("Item2", groupB));
groupB.Header = "B - 1 item";
}
private void button2_Click(object sender, EventArgs e)
{
//Clear the items
listView1.Items.Clear();
//Update header
//The problem here is that the headers are not displayed any more
groupA.Header = "A - 0 item";
groupB.Header = "B - 0 item";
}