2013-11-04 67 views
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"; 
    } 
+0

您需要一些「虛擬」物品才能觸及組羣。它應該小心翼翼地完成,以使其順利自動運行,我認爲你需要相當多的自定義代碼(幾乎與某些事件有關)。 –

回答

0

我回答我的問題!這似乎不可能用正常的ListView來完成。我也看到了底層的Win32消息,但沒有成功。最後,我放棄了,我買了第三方控制。

相關問題