我试图对TListView对象中的项进行分组,但是我找不到负责对对象进行分组的类,在文档中也找不到。
该平台是Fire猴子( Android/iOS) / Delphi XE6
发布于 2014-08-01 12:29:26
我认为您所指的属性是TListGroups,一个包含TListGroup项的集合。德尔菲文档中提供了一个演示。
不幸的是,它只能在VCL中使用,而不是FMX,因为底层功能是TListView封装的TListView控件的一部分。
在FMX中最接近的是使用TListBox和TListBoxGroupHeader,这在使用ListBox组件在多维基中显示表视图(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的图像)

发布于 2019-01-08 19:36:29
这在FMX TListview控件中很容易实现,同时通过将您的TListviewItem.header.break字段连接到您想要分组的字段(它将成为数据库中的一个对许多记录来说是冗余的字段),从而使用TListviewItem.header.break绑定。
https://stackoverflow.com/questions/25079633
复制相似问题