我想知道是否可以将TList对象绑定为cxGrid数据源。
因此,我拥有的是一个TList对象,其中包含我不需要持久化的各种对象。我想要一种GridView作为"selected items“的概述,而所选的items是列表中的对象。
最好是由存储在TList中的对象类型来定义列。
这是容易做到的,如果是这样,你能给我一个如何做到这一点的概述。我目前使用的ListBox使用tabWidth作为一种列分隔符,但我更愿意进行切换。
发布于 2011-11-02 02:21:57
Quantum Grid有三种不同的数据访问方式。它可以在未绑定(直接访问单元格)、绑定(使用数据源的标准方式)或“提供者”模式下工作,在这种模式下,您必须编写适当的类(提供者)来访问和修改数据。在提供程序模式下,数据源可以是您喜欢的任何一个。帮助详细介绍了如何实现提供程序。在演示应用程序中,THere也应该是一个UnboundListDemo。
发布于 2012-01-15 10:14:27
假设您有一个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;https://stackoverflow.com/questions/7970017
复制相似问题