3

我想知道是否可以将 TList 对象绑定为 cxGrid 数据源。

所以我拥有的是一个 TList 对象,其中包含我不需要持久的各种对象。我想要一种 GridView 作为“所选项目”的概述,并且所选项目是列表中的对象。

最好由存储在 TList 中的对象类型定义列。

这是否容易实现,如果可以,您能否给我一个关于如何完成的概述。我目前正在使用一个 ListBox,它使用 tabWidth 作为一种列分隔符,但更愿意进行切换。

4

2 回答 2

3

假设您有一个 TList 派生类 TMyList,它包含 TMyListItem 类的项目。然后,您将从 TcxCustomDataSource 派生。

  TTListDataSource = class(TcxCustomDataSource)
       private
          FTList  : TMyList;
       protected
          function GetRecordCount: Integer; override;
          function GetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle): Variant; override;
       public
          constructor Create(ATList : TMyList);
   end;

实现将是这样的:

constructor TTListDataSource.Create(ATList : TMyList);
begin
   inherited Create;
   FTList := ATList;
end;

function TTListDataSource.GetRecordCount: Integer;
begin
   result := FTList.Count;
end;

function TTListDataSource.GetValue(ARecordHandle: TcxDataRecordHandle;
                                   AItemHandle: TcxDataItemHandle): Variant;
var
   aIndex         : Integer;
   aMyListItem    : TMyListItem;
begin
   aCurrentIndex  := Integer(ARecordHandle);
   if (aCurrentIndex > -1)  and (aCurrentIndex < FTList.Count) then begin
      aMyListItem    := FTList[aCurrentIndex)] as TMyListItem;
      aIndex         := Integer(AItemHandle);
      case aIndex of
         0                  : result := '';
         1                  : result := aMyListItem.Year;
         2                  : result := aMyListItem.Quarter;
      end
      else
         result := '';
end;

你会使用你的课程:

   FTListDataSource := TTListDataSource.Create(ATList);
   ThePivotGrid.DataController.CustomDataSource := FTListDataSource;
   FTListDataSource.DataChanged;
于 2012-01-15T02:14:27.487 回答
2

Quantum Grid 具有三种不同的数据访问方式。它可以在未绑定(您直接访问单元格)、绑定(使用数据源的标准方式)或“提供者”模式下工作,您必须编写适当的类(提供者)来访问和修改数据。在提供者模式下,数据源可以是任何你喜欢的。帮助详细说明了如何实现提供程序。演示应用程序中也应该有一个 UnboundListDemo。

于 2011-11-01T18:21:57.263 回答