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];
 end;

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);
begin
    if (ARecord.Values[TableViewID_MONEY.Index])=null then begin
        AStyle :=cxStyleBold;
    end;
end;

Coloring different grouping levels in different colors

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

The lack of coloring through the styles (Style) in that the cursor overlaps the coloring. This can be bypassed if in the TableViewCustomDrawCell handler make the selection of the line itself (for CellSelect = True):

  if AViewInfo.GridRecord.Selected then begin
    if AViewInfo.Selected then begin // under the inverse cursor, make the white font
      ACanvas.Font.Color := clWhite;
    end else begin // The rest of the line will be highlighted in blue font so as not to overwrite the background
      ACanvas.Font.Color := clBlue;
      ACanvas.Font.Style := [fsBold];
    end;
  end;

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.Clear;
GridDBTableView1.DataController.Filter.Root.AddItem(GridDBTableView1.Columns[0], cxFilter.foLike,nomzak+"%",nomzak+"%");
GridDBTableView1.DataController.Filter.Active:=true;

Expand and collapse groups in runtime

TableView.DataController.Groups.FullCollapse;
TableView.DataController.Groups.FullExpand;
TableView.DataController.Options := TableView.DataController.Options + [dcoGroupsAlwaysExpanded]; // fix expand state

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
cxGrid.DataController.Values[cxGrid.DataController.FilteredRecordIndex[i],YourColumnName.Index])

 

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];
end;

Get column grid on its behalf

TableView1.GetColumnByFieldName('FIELD_NAME')

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:

TcxComboBoxProperties(NTableViewKMPNAME.Properties).Items.Clear;
while not LookupQuery.Eof do begin
TcxComboBoxProperties(NTableViewKMPNAME.Properties).Items.Add(LookupQuery['NM_NAME']);
LookupQuery.Next;
end;

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:

var
XCol : TcxGridDBBandedColumn;
begin
XCol := TableView.CreateColumn;
XCol.Position.BandIndex := 1;
XCol.DataBinding.FieldName:='quant'+sl[i];
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:

TableView.Columns[i].Destroy;

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 *