Skip to main content

Group Management: Ungrouping Rows and/or Columns

  • 3 minutes to read

The Spreadsheet Control provides multiple options for ungrouping the columns and rows:

The Delete procedure, implemented in the TdxSpreadSheetTableItemGroups class, can perform the following actions:

  • Delete the entire group of table items at the highest nesting level if the AStartIndex and AFinishIndex parameters match the group’s StartIndex and FinishIndex property values:

Remove Group

  • Shrink the group of columns or rows if either the AStartIndex or AFinishIndex parameter matches the group’s StartIndex or FinishIndex property value:

Shrink Group

  • Split the target group into two groups of columns or rows if the range of table items specified by using the AStartIndex and AFinishIndex parameters, lies within the grouped range specified as the group’s StartIndex and FinishIndex property values:

Divide Group

To allow an end-user to ungroup columns and rows, you can use the information on selected areas within the currently active worksheet. For instance, an implementation of the ungroup command can use the left and right bounds of the Table View worksheet’s Selection.Area rectangle as the AStartIndex and AFinishIndex parameters of the Columns.Groups.Delete 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.Delete(AFirstColumn, ALastColumn);

In the case of row ungrouping, you can use the top and bottom bounds of the same Selection.Area rectangle as the AStartIndex and AFinishIndex parameters of the Rows.Groups.Delete 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.Delete(AFirstColumn, ALastColumn);

To implement the “ungroup all columns” and “ungroup all rows” commands, use the Table View‘s Columns.Groups.DeleteAll and Rows.Groups.DeleteAll procedures, respectively.