Programmatically adding columns to a TdxDBGrid (Expressquantumgrid by Devexpress)

2.1k views Asked by At

With a customer I'm stuck developing for this very old version (2.1) of ExpressQuantumGrid by DevExpress. In Delphi 4. I can't find any documentation about it.

Basically I just need to create a bunch of TdxDBGridMaskColumn and "insert" them into the grid (TdxDBGrid) at runtime. From the code completion pop-up I can't figure out how.

Thanks!

1

There are 1 answers

0
SteB On

We have an old app that uses Delphi 5 and DevExpress v3, the code might not be identical but should get you started.

A function that can create a column of any type (TdxDBDateColumn for example):

function CreateColumn(const aField: string; aColClass: TdxDBTreeListColumnClass): TdxDBTreeListColumn;
var
begin
  Result := dxGrid.CreateColumn(aColClass);
  Result.Name := dxGrid.Name + aField;
  TdxDBGridColumn(Result).DisableFilter := True;
  TdxDBGridColumn(Result).DisableGrouping := True;
  TdxDBGridColumn(Result).Alignment := taRightJustify;
  TdxDBGridColumn(Result).FieldName := aField;
  TdxDBGridColumn(Result).Caption := aField;
  TdxDBGridColumn(Result).Width := 70;
end;

Then you can call this function like so:

NewColumn := CreateColumn('Username', TdxDBGridColumn);