Group Management: Ungrouping Rows and/or Columns
- 3 minutes to read
The Spreadsheet Control provides multiple options for ungrouping the columns and rows:
To delete all table item groups previously created within the root node (i.e., ungroup all columns or rows within the Table View simultaneously), invoke the DeleteAll procedure implemented in the TdxSpreadSheetTableItemGroups class;
To delete all groups nested within a particular group, invoke the DeleteAll procedure implemented in the TdxSpreadSheetTableItemGroup class;
To exclude a specified table item range from an individual group at the highest nesting level, call the Delete procedure implemented in the TdxSpreadSheetTableItemGroups class. You can also use this method to shrink a table item group or to split it into two or more groups;
To shrink a group, you can increase its StartIndex property value and/or decrease its FinishIndex property value.
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:
- Shrink the group of columns or rows if either the AStartIndex or AFinishIndex parameter matches the group’s StartIndex or FinishIndex property value:
- 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:
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.