首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用TList作为DataSource的tcxGrid

使用TList作为DataSource的tcxGrid
EN

Stack Overflow用户
提问于 2011-11-02 01:03:02
回答 2查看 5.3K关注 0票数 3

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

因此,我拥有的是一个TList对象,其中包含我不需要持久化的各种对象。我想要一种GridView作为"selected items“的概述,而所选的items是列表中的对象。

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

这是容易做到的,如果是这样,你能给我一个如何做到这一点的概述。我目前使用的ListBox使用tabWidth作为一种列分隔符,但我更愿意进行切换。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-02 02:21:57

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

票数 2
EN

Stack Overflow用户

发布于 2012-01-15 10:14:27

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

代码语言:javascript
复制
  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;

其实现如下所示:

代码语言:javascript
复制
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;

你可以使用你的类:

代码语言:javascript
复制
   FTListDataSource := TTListDataSource.Create(ATList);
   ThePivotGrid.DataController.CustomDataSource := FTListDataSource;
   FTListDataSource.DataChanged;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7970017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档