グループ内のアイテムの数 (0 アイテムを含む) を示すグループ ヘッダーを使用して、リスト ビュー (winform) でアイテムをグループ化したいと考えています。私の問題は、グループまたはリスト ビューからアイテムをクリアすると、グループ ヘッダーが消えることです。
グループ ヘッダーが消えないようにするにはどうすればよいですか? 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";
}