Skip to main content

Group Management: Row and Column Grouping

  • 3 minutes to read

To create a new group of columns or rows within the current worksheet, call the Add procedure accessible via the Table View‘s Columns.Groups and Rows.Groups properties, respectively. The first overloaded version of this method allows you to create a new group containing a single specified row or column while the second overloaded version creates a group from a continuous range of table items:

Row Groups

If the specified range of table items already belongs to one of the previously created groups, the Add procedure creates a new group with a higher nesting level:

Create Nested Groups

If the Add procedure is attempting to create a table item group with an outline (node) level exceeding the dxSpreadSheetMaxOutlineLevel global constant value, the EdxSpreadSheetError exception is raised:

Exception Message Box

Two individual row or column groups must be separated by at least a single row or column that does not belong to any group at the current nesting level:

Interval between Groups

Otherwise, the newly created group is merged with the neighboring group of table items at the same nesting level:

Merge Groups

To extend the range of columns or rows enclosed by the existing group, you can use the Table View‘s Columns.Groups.Add or Rows.Groups.Add procedures, respectively. The alternative use of this method allows you to extend a group with one or more table items that do not belong to any group at the current nesting level. Either the beginning or end of the non-grouped table items range must be adjacent to the target group:

Expand Groups

Otherwise, the Add procedure can create either a separate group on the same nesting level or a group nested within the target group, depending on the table item range’s actual location:

Interval between Groups

To allow an end-user to create row or column groups, you can use the information on selected areas within the currently active worksheet. For instance, an implementation of the add column group command can use the left and right bounds of Table View‘s Selection.Area rectangle as the AStartIndex and AFinishIndex parameters of the Columns.Groups.Add procedure, respectively:

var
  ATableView: TdxSpreadSheetTableView;
  AFirstColumn, ALastColumn: Integer;
//...
  ATableView := dxSpreadSheet1.ActiveSheetAsTable;
  AFirstColumn := ATableView.Selection.Area.Left;
  ALastColumn := ATableView.Selection.Area.Right;
  if(ATableView.Selection.Count > 0) then
    ATableView.Columns.Groups.Add(AFirstColumn, ALastColumn);

In the case of row grouping, you can use the top and bottom bounds of the same Selection.Area rectangle as the AStartIndex and AFinishIndex parameters of the Rows.Groups.Add procedure, respectively:

var
  ATableView: TdxSpreadSheetTableView;
  AFirstRow, ALastRow: Integer;
//...
  ATableView := dxSpreadSheet1.ActiveSheetAsTable;
  AFirstRow := ATableView.Selection.Area.Top;
  ALastRow := ATableView.Selection.Area.Bottom;
  if(ATableView.Selection.Count > 0) then
    ATableView.Rows.Groups.Add(AFirstRow, ALastRow);