添加记录编号时跳过组行

时间:2012-10-06 16:55:27

标签: delphi devexpress tcxgrid

我有以下代码在cxGrid中添加'recordnumbers',但它有不必要的副作用,如果它是一个带分组的网格,那么每次有GroupRow时它会步进一个数字然后有一个缺失的数字。 任何避免这种方法的方法

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;

2 个答案:

答案 0 :(得分:1)

在行之前减去组的数量应该如下:

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;

您需要+1中的GrIdx,因为当没有群组​​时,群组索引为-1,第一群组的索引为0,依此类推。

答案 1 :(得分:0)

这应该有用(没有测试,写出内存......):

procedure TfrmProjectTasksActive.colCountGetDisplayText(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AText: string);
var
  Row: integer;
  aRowInfo : TcxRowInfo;
begin
  aRowInfo := ARecord.GridView.DataController.GetRowInfo(ARecord.Index);
  if not (aRowInfo.Level < ARecord.GridView.DataController.Groups.GroupingItemCount) then //test, if Row is not a group-row
  begin
    Row := Sender.GridView.DataController.GetRowIndexByRecordIndex(aRecord.RecordIndex, False);
    aText := Format('%.*d', [3, (Row + 1)]);
  end;
end;

希望我能正确地理解它,如果它没有开箱即用,那就很抱歉。但是“aRowInfo”至少应该给你正确的提示......另外:注意“ARecord”的“Index”和“RecordIndex”之间的区别。