gpt4 book ai didi

delphi - 在TListView对象内对项目进行分组?

转载 作者:行者123 更新时间:2023-12-01 21:48:05 31 4
gpt4 key购买 nike

我正在尝试将TListView对象中的项目进行分组,但是找不到负责分组对象的类,也无法在文档中找到此类。


什么是负责对TListView对象内的项目进行分组的类,以及如何正确使用它?


该平台是Firemonkey(Android / iOS)/ Delphi XE6

最佳答案

我相信您所指的属性是TListGroups,该集合包含TListGroup个项目。 Delphi文档中提供了demo

不幸的是,它仅在VCL中可用,而在FMX中不可用,因为基本功能是TListView包装的Windows ListView控件的一部分。

在FMX中,最接近的是使用TListBoxTListBoxGroupHeader,《使用清单框组件在docwiki中显示表视图(iOS和Android)的多设备教程》中对此进行了介绍:

procedure TForm1.FormCreate(Sender: TObject);
var
c: Char;
i: Integer;
Buffer: String;
ListBoxItem : TListBoxItem;
ListBoxGroupHeader : TListBoxGroupHeader;
begin
ListBox1.BeginUpdate;
for c := 'a' to 'z' do
begin
// Add header ('A' to 'Z') to the List
ListBoxGroupHeader := TListBoxGroupHeader.Create(ListBox1);
ListBoxGroupHeader.Text := UpperCase(c);
ListBox1.AddObject(ListBoxGroupHeader);

// Add items ('a', 'aa', 'aaa', 'b', 'bb', 'bbb', 'c', ...) to the list
for i := 1 to 3 do
begin
// StringOfChar returns a string with a specified number of repeating characters.
Buffer := StringOfChar(c, i);
// Simply add item
// ListBox1.Items.Add(Buffer);

// or, you can add items by creating an instance of TListBoxItem by yourself
ListBoxItem := TListBoxItem.Create(ListBox1);
ListBoxItem.Text := Buffer;
// (aNone=0, aMore=1, aDetail=2, aCheckmark=3)
ListBoxItem.ItemData.Accessory := TListBoxItemData.TAccessory(i);
ListBox1.AddObject(ListBoxItem);
end;
end;
ListBox1.EndUpdate;
end;


产生(来自指定docwiki的图像)

关于delphi - 在TListView对象内对项目进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25079633/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com