2010-05-30 86 views

回答

4

這可能是最簡單的方法。

procedure TForm1.Click(Sender: TObject); 
begin 
    ShowMessage(IntToStr(GetNumItemsInGroup(1))); 
end; 

function TForm1.GetNumItemsInGroup(const GroupID: integer): integer; 
var 
    i: Integer; 
begin 
    result := 0; 
    assert((GroupID >= 0) and (GroupID <= ListView1.Groups.Count - 1)); 
    for i := 0 to ListView1.Items.Count - 1 do 
    if ListView1.Items.Item[i].GroupID = GroupID then 
     inc(result); 
end; 
+0

謝謝你..這很好地工作。 – Bill 2010-05-30 02:11:07

1

在Vista和後止,LVM_GETGROUPINFOLVM_GETGROUPINFOBYINDEX消息返回具有cItems部件指定所述組中的項的數目的LVGROUP結構。

+0

這是一個更好的解決方案。特別是,在非常大的列表視圖中,它可能會快得多。然而,根據我的經驗,列表視圖組在大量數據方面效果不佳,所以這種差異在實踐中可能並不重要。 – 2017-12-30 11:39:42