0
我想将列表视图(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";
}
您需要一些“虚拟”物品才能触及组群。它应该小心翼翼地完成,以使其顺利自动运行,我认为你需要相当多的自定义代码(几乎与某些事件有关)。 –