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

标签 delphi firemonkey delphi-xe6

我正在尝试将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/

相关文章:

multithreading - TRTTIContext多线程问题

delphi - 在 Firemonkey 中打印时客户端的格式设置发生变化

delphi - 如何在 Delphi 7 中使用 SQL Server Service Broker/SQL 通知?

delphi - Delphi 中的自定义控件创建

delphi - 如何在 Firemonkey 中设计时设计 TFrame 样式

FireMonkey 中的 Delphi XE4 stringgrid 选择单元

delphi - 如何手动将 html-help 文件注册到 Delphi (RAD Studio) XE6 在线文档中?

delphi - 错误: F1026 File not found: 'System.Actions.dcu' switching back to Delphi XE2 from XE3

delphi - 序列化 TdwsProgram

delphi - 如何在firemonkey下将一些代码排队在下一个周期执行?