Let's assume that you have a TList derived class TMyList, that holds items of TMyListItem class.
You would then derive from 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;
The implementation would be like this:
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;
And you would use your class:
FTListDataSource := TTListDataSource.Create(ATList);
ThePivotGrid.DataController.CustomDataSource := FTListDataSource;
FTListDataSource.DataChanged;