开发者

Count the number of items in a TListview Group

When I attempt to count the number of items in a group I get the total number of item开发者_开发问答s in the collection. How do you get the number of items in each group?


This is probably the simplest way.

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;


Under Vista and later only, the LVM_GETGROUPINFO and LVM_GETGROUPINFOBYINDEX messages return a LVGROUP structure that has a cItems member specifying the number of items in the group.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜