Skip to main content
A newer version of this page is available. .

Expanding and Collapsing Rows

  • 3 minutes to read

Each row in a vertical grid control (VGridControl or PropertyGridControl) can have a number of child rows, so rows can be expanded and collapsed to show or hide their children respectively. This topic describes the means by which they can be collapsed or expanded.

Collapsing and Expanding Rows

Rows in the vertical grids inherit the ability to contain child rows and to be the children of other rows from their common ancestor - the BaseRow class. Amongst other settings, this class declares the BaseRow.Expanded property which can be used to collapse or expand rows and to determine their current state. To expand a row, you must set its BaseRow.Expanded property to true, setting it to false will collapse the row. The image below shows how to change the expanded state of a row at design time.

ExpandCollapse - DesignTime_New

To change the expanded state for a specific row at runtime you need to obtain its row object and modify the BaseRow.Expanded property value.

The code line below shows how to collapse the rowMain row.


rowMain.Expanded = false;

Note that the BaseRow.Expanded row property value doesn’t affect the expanded state of a row’s child rows. For instance, expanding a row that has collapsed child rows will not expand its children. So, if you collapse a row, all child rows will retain their expanded state and will appear in these states again when their parents are expanded.

In addition to expanding and collapsing individual rows, the vertical grid enables you to expand a row together with all of its child rows. This can be performed using the VGridControlBase.FullExpandRow method that requires a row as the parameter.

The line of code below demonstrates how to use the VGridControlBase.FullExpandRow method to expand the rowMain row together with all its children.


vGridControl1.FullExpandRow(rowMain);

To expand or collapse all rows, use the VGridControlBase.ExpandAllRows and VGridControlBase.CollapseAllRows methods.

When designing applications using the vertical grids you can expand or collapse rows which satisfy a specific condition. This can be performed by means of the Rows Iterator technology introduced by the vertical grid control. This technology provides an easy way of traversing through control rows and performing operations on them. Please refer to the Using the Rows Iterator topic for more information regarding this.

The following sample code is used to collapse all rows that do not contain the focused row as the child. So as a result only rows that are parents of the focused row are expanded, to implement this the new operation class used by the rows iterator is declared and its instance is passed to the VGridRowsIterator.DoOperation method of the iterator.


// running the operation that collapses all rows that are not parents of the specified one
vGridControl1.RowsIterator.DoOperation(new CollapseExceptSpecifiedOperation(vGridControl1.FocusedRow));

// the operation class used to perform the task
public class CollapseExceptSpecifiedOperation : RowOperation {
   BaseRow visibleRow;
   public CollapseExceptSpecifiedOperation(BaseRow visibleRow) : base() {
      this.visibleRow = visibleRow;
   }
   public override void Execute(BaseRow row) {
      if (!row.HasAsChild(visibleRow))
         row.Expanded = false;
   }
   public override bool NeedsFullIteration { get { return false; } }
}