0

我有以下代码在 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;
4

2 回答 2

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;

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

于 2012-10-07T10:17:19.877 回答
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”之间的区别。

于 2012-10-06T18:44:06.797 回答