0

I use TcxGrid But I cant create fields on execution time because I have a pivot query and columns are variable

Can I fill cxGrid like tDbGrid?

Rapunzo
  • 966
  • 5
  • 21
  • 42

3 Answers3

5

I solved the problem like this

grdCevapDBTableView2.BeginUpdate;
grdCevapDBTableView2.ClearItems;
fillGridView(grdCevapDBTableView2,command);
grdCevapDBTableView2.DataController.CreateAllItems;
grdCevapDBTableView2.EndUpdate;
Rapunzo
  • 966
  • 5
  • 21
  • 42
4

I like to use the TcxGrid.DataController.CreateAllItems method which creates all columns that exists in the datasource. It takes a boolean parameter with which you can decide wether to add all columns or only those missing.

johnny
  • 657
  • 7
  • 18
1

Try something like this:

function TForm1.AddIntegerColumn(const ACaption, AName: string): TcxGridColumn;
begin
  Result := TableView.CreateColumn;
  Result.DataBinding.ValueTypeClass := TcxIntegerValueType;
  Result.Caption := ACaption;
  Result.Name := AName;
end;
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83