I have the following code to add 'recordnumbers' in a cxGrid but it has the unwanted sideefeect that if it is a grid with grouping then it step one number every time there is a GroupRow and then there is a missing number. Any ways to avoid this
procedure TfrmProjectTasksActive.colCountGetDisplayText(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AText: string);
var
Row: integer;
begin
Row := Sender.GridView.DataController.GetRowIndexByRecordIndex(aRecord.RecordIndex, False);
aText := Format('%.*d', [3, (Row + 1)]);;
end;
Subtracting the number of groups before the row should work then, something like:
procedure TfrmProjectTasksActive.colCountGetDisplayText(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AText: string);
var
Row, GrIdx: integer;
begin
Row := Sender.GridView.DataController.GetRowIndexByRecordIndex(aRecord.RecordIndex, False);
GrIdx := Sender.GridView.DataController.Groups.DataGroupIndexByRowIndex[Row] + 1;
aText := Format('%.*d', [3, (Row + 1 - GrIdx)]);
end;
You need the +1
in the GrIdx
because when there is no groups then group index is -1
, first group has a index 0
and so on.