Crib on DevExpress cxGrid and Delphi 7

Some techniques for working with the component cxGrid, collected from various sources and helpful to me personally.

Outward appearance

SOFTWARE coloring of cells can be done in the events OnCustomDrawCell

if (AViewInfo.GridRecord.Values[TableViewColumn1.Index])=1 then begin
   ACanvas.Brush.Color := clRed;
   ACanvas.Font.Style := [fsBold];

If you want to paint only the individual speakers (instead of the entire line), then paint the column handler OnCustomDrawCell can be defined as:

if TableView.Columns[AViewInfo.Item.Index].DataBinding.FieldName='COLUMN_1' then

The only thing you need to consider that this coloring is not displayed when exported to Excel. You need to paint solely assigning predetermined “style” type handlers “TableViewStylesGet***Style”:

procedure TMoneyMoveDetailForm.TableViewStylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    if (ARecord.Values[TableViewID_MONEY.Index])=null then begin
        AStyle :=cxStyleBold;

Coloring different grouping levels in different colors

procedure TPozSkladForm.TableViewStylesGetGroupStyle(
Sender: TcxGridTableView; ARecord: TcxCustomGridRecord; ALevel: Integer;
out AStyle: TcxStyle);
    if ALevel=0 then AStyle := cxStyleL0;  // $00A0A0A0
    if ALevel=1 then AStyle := cxStyleL1;  // clSilver
    if ALevel=2 then AStyle := cxStyleL2;  // $00E0E0E0

Display data (filters, grouping, sorting)

In TcxGrid group GroupByBox hide and clean the area on a grid in which it is written “drag a column header here to group by ..”

TableView.OptionsView.GroupByBox := false;

Programmatically set the Filter:

GridDBTableView1.DataController.Filter.Root.AddItem(GridDBTableView1.Columns[0], cxFilter.foLike,nomzak+"%",nomzak+"%");

Access to data and metadata Grid

run in a loop through all the visible lines:

for I:=0 to cxGrid.DataController.FilteredRecordCount - 1 do begin


Loop through all selected lines to give each identifier

for i := 0 to GridView1.Controller.SelectedRecordCount-1 do begin
ID_RASHODD := GridView1.DataController.Values[GridView1.Controller.SelectedRecords[i].RecordIndex, GridView1ID_RASHODD.Index];

Get column grid on its behalf


Edit user data

Organization list ComboBox to the cell:

Properties set in the ComboBox, fill in the list of events AfterScroll dataset, if it try to do in onInitPopUp the list of previous falls (?). How to fill in:

while not LookupQuery.Eof do begin

User selection is verified and used in the method OnValidate

Editing numbers in the grid

In the Properties view and set CalcEdit handler OnEditValueChanged yuzaem (Sender as TcxCalcEdit) .Value and the current situation in the dataset

To catch right click on a particular column:

in the event OnCellClick:

if ACellViewInfo.Item.Name='DzTableViewNRM_NAME' then
if AButton=mbRight then

Processing mark the check-box in the cell. In the event OnChange:

if (Sender as TcxCheckBox).Checked then

Changing tables in runtime

Adding columns in runtime:

XCol : TcxGridDBBandedColumn;
XCol := TableView.CreateColumn;
XCol.Position.BandIndex := 1;
XCol.DataBinding.ValueType := 'Float';
XCol.Caption := ss[i];
XCol.Width := 50;
XCol.Tag := StrToInt(sl[i]);
XCol.Summary.FooterKind := skSum;
XCol.Summary.GroupFooterKind := skSum;
XCol.Summary.GroupKind := skSum;
XCol.Summary.FooterFormat := '0.##';
XCol.Summary.GroupFooterFormat := '0.##';
XCol.Summary.GroupFormat := '0.##';

Removing column runtime:


Adding gang (bands):

b0 := TableView.Bands.Add;
b0.Position.BandIndex := b.Index;
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *