Back to Devexpress

TcxPivotGridViewDataSelection.Regions Property

vcl-cxcustompivotgrid-dot-tcxpivotgridviewdataselection.md

latest3.9 KB
Original Source

TcxPivotGridViewDataSelection.Regions Property

Provides indexed access to cell regions making up the current selection.

Declaration

delphi
property Regions[AIndex: Integer]: TRect read; default;

Property Value

Type
TRect

Remarks

To manage regions within the Regions collection, call the Add, MakeNew, Delete, and Clear methods. The Count property returns the number of items within this collection. Changes to this collection fire the pivot grid’s OnSelectionChanged event.

The following code example shows how to iterate through the Regions collection to calculate the sum of selected data cell values excluding subtotal and grand total values.

delphi
procedure <Form>.Button1Click(Sender: TObject);
var
  I,X,Y,RightX,BottomY: Integer;
  ASelection: TRect;
  ACellSummary: Variant;
begin
  ACellSummary := 0;
  with PivotGrid.ViewData do
  begin
    for I := 0 to Selection.Count - 1 do
    begin
      ASelection := Selection.Regions[I];
      RightX := Min(ASelection.Right, ColumnCount - 1);
      BottomY := Min(ASelection.Bottom, RowCount - 1);
      for X := ASelection.Left to RightX do
      begin
        for Y := ASelection.Top to BottomY do
          if not (Rows[Y].IsTotalItem or Columns[X].IsTotalItem) then
            ACellSummary := ACellSummary + Cells[Y,X].Sum;
      end;
    end;
  end;
  ShowMessage(VarToStr(ACellSummary));
end;
cpp
void __fastcall <Form>::Button1Click(TObject *Sender)
{
  Variant ACellSummary = 0;
  TcxPivotGridViewData *AViewData = PivotGrid->ViewData;
  int RightX,BottomY;
  for(int I = 0; I < AViewData->Selection->Count; I++) {
    TRect ASelection = AViewData->Selection->Regions[I];
    RightX = Min(ASelection.Right, AViewData->ColumnCount - 1);
    BottomY = Min(ASelection.Bottom, AViewData->RowCount - 1);
    for(int X = ASelection.Left; X <= RightX; X++) {
      for(int Y = ASelection.Top; Y <= BottomY; Y++) {
        if(!AViewData->Rows[Y]->IsTotalItem &&
          !AViewData->Columns[X]->IsTotalItem) {
          ACellSummary = ACellSummary + AViewData->Cells[Y][X]->Sum;
        }
      }
    }
  }
  ShowMessage(VarToStr(ACellSummary));
}

See Also

TcxPivotGridOptionsSelection.HideSelection

TcxPivotGridViewDataSelection.BeginUpdate

TcxPivotGridViewDataSelection.EndUpdate

TcxPivotGridViewDataSelection.FocusedCell

TcxPivotGridViewDataSelection.GetCombinedSelectionBounds

TcxPivotGridViewDataSelection.IsCellSelected

TcxPivotGridViewDataSelection.Regions

TcxPivotGridViewDataSelection Class

TcxPivotGridViewDataSelection Members

cxCustomPivotGrid Unit