0

cxGrid に 'recordnumbers' を追加する次のコードがありますが、グループ化されたグリッドの場合、GroupRow が存在するたびに 1 つの数値がステップアップし、数値が欠落しているという望ましくない副作用があります。これを回避する方法

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;

グループがない場合、グループインデックスは、最初のグループにはインデックスがあるなど+1の理由で、が必要です。GrIdx-10

于 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 に答える