//Delphi
procedure TForm1.ButtonLevelUpClick(Sender: TObject);
var
ARecord: TcxCustomGridRecord;
begin
with TcxCustomGridTableView(Grid.FocusedView) do
begin
ARecord := Controller.FocusedRecord;
if Assigned(ARecord) then
begin
ARecord := ARecord.ParentRecord;
if Assigned(ARecord) then
ARecord.Focused := True;
end;
end;
end;
//Delphi
procedure TForm1.ButtonLevelDownClick(Sender: TObject);
function GetFirstChild(ARecord: TcxCustomGridRecord): TcxCustomGridRecord;
begin
if ARecord is TcxGridMasterDataRow then
Result := ARecord.GetFirstFocusableChild
else
if ARecord is TcxGridGroupRow then
Result := ARecord.ViewData.Records[ARecord.Index + 1]
else
Result := nil;
end;
var
ARecord: TcxCustomGridRecord;
begin
with TcxCustomGridTableView(Grid.FocusedView) do
begin
ARecord := Controller.FocusedRecord;
if Assigned(ARecord) then
begin
ARecord.Expand(False);
ARecord := Controller.FocusedRecord;
ARecord := GetFirstChild(ARecord);
if Assigned(ARecord) then
ARecord.Focused := True;
end;
end;
end;
如TableView是为TcxDBTableView的话,那
TableView.DataController.Groups.ChildCount(1); //这里得到的是第一个组的总数
看看下面我以前写的一段代码
for i := 0 to Tableview.Controller.SelectedRowCount - 1 do
begin
//判断选择的是否为组的行
if TableView.Controller.SelectedRows[i] is TcxGridGroupRow then
begin
//取得组的行的index;
GRowIndex := TableView.Controller.SelectedRows[i].Index;
//取得组的行的ID;
GRowID := TableView.DataController.Groups.DataGroupIndexByRowIndex[GRowIndex];
//这里得到的是组的行的那个标题
ShowMessage(TableView.DataController.Groups.GroupValues[GRowID]);
//这里是组的行数
ShowMessage(IntToStr(TableView.DataController.Groups.ChildCount[GRowID]));
end;
end;
end;
procedure TForm1.CalculateGroupAverage(ADataGroupIndex: TcxDataGroupIndex);
var
AMengeTo, AGesamt, AVarAverage: Variant;
begin
with gv.DataController.Summary do
begin
AMengeTo := GroupSummaryValues[ADataGroupIndex, 2];
AGesamt := GroupSummaryValues[ADataGroupIndex, 0];
if not (VarIsNull(AMengeTo) or VarIsNull(AGesamt)) then
begin
AVarAverage := AGesamt / AMengeTo;
GroupSummaryValues[ADataGroupIndex, 3] := FloatToStrF(AVarAverage, ffFixed, 15, 2);
end;
end;
end;
procedure TForm1.gvDataControllerSummaryAfterSummary(
ASender: TcxDataSummary);
var
AChildDataGroupsCount: Integer;
AChildDataGroupIndex, AParentDataGroupIndex: TcxDataGroupIndex;
AChildPosition: Integer;
i: Integer;
begin
with TcxDataControllerGroups(gv.DataController.Groups) do
begin
for i := 1 to GroupingItemCount do
begin
AChildDataGroupsCount := ChildCount[i -2];
for AChildPosition := 0 to AChildDataGroupsCount - 1 do
begin
AChildDataGroupIndex := ChildDataGroupIndex[i -2, AChildPosition];
CalculateGroupAverage(AChildDataGroupIndex);
end;
end;
end;
end;