Skip to main content

GridControl.CollapseMasterRow(Int32, DetailDescriptorBase) Method

Collapses the detail section for the specified row.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v22.1.dll


public void CollapseMasterRow(
    int rowHandle,
    DetailDescriptorBase descriptor = null


Name Type Description
rowHandle Int32

An integer value identifying the row by its handle.

Optional Parameters

Name Type Default Description
descriptor DetailDescriptorBase


Optional. A DetailDescriptorBase object specifying the detail. This parameter is not used and defaults to null (Nothing in Visual Basic). Use the CollapseMasterRow method with only the rowHandle parameter.


This method can be used when implementing custom controls that control Detail section visibility. In this case, you might want to hide default expand buttons by disabling the TableView.ShowDetailButtons option.

This method may have no effect if overridden in the GridControl.MasterRowCollapsing event handler.

To determine the expanded state of master rows and Detail visibility, use the GridControl.IsMasterRowExpanded, GridControl.GetVisibleDetail and GridControl.GetVisibleDetailDescriptor methods.


This sample shows you a few members that allow expanding and collapsing master rows. Keyboard presses are processed to allow the CTRL+* shortcut to toggle the currently focused master row’s state. There are also two buttons - one allowing expansion of all master rows, and another that collapses details for all but the focused row.

The following members are used in this example:

Member Description
GridControl.CollapseMasterRow Collapses the detail section for the specified row.
GridControl.ExpandMasterRow Expands the specified master row and, optionally, shows the specified Detail.
GridControl.IsMasterRowExpanded Determines the specified master row’s expanded state and, optionally, the specified Detail’s visibility.
GridControl.SetMasterRowExpanded Changes the expanded state for a specified master row and, optionally, shows a specified Detail.

View Example

Private Sub TableView_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
    Dim view As TableView = TryCast(sender, TableView)

    ' Avoid key processing when focus is within detail views
    ' or when a groupo row is focused
    If Not view.IsFocusedView OrElse view.FocusedRowHandle < 0 Then
    End If

    ' Process CTRL+* key combination
    If e.Key = Key.Multiply AndAlso ((Keyboard.Modifiers And ModifierKeys.Control) = ModifierKeys.Control) Then
        Dim finalExpandedState As Boolean = Not view.Grid.IsMasterRowExpanded(view.FocusedRowHandle)
        view.Grid.SetMasterRowExpanded(view.FocusedRowHandle, finalExpandedState)
        e.Handled = True
    End If
End Sub
Private Sub buttonExpandAll_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    For i As Integer = 0 To gridControl1.VisibleRowCount - 1
        Dim rowHandle = gridControl1.GetRowHandleByVisibleIndex(i)
    Next i
End Sub
Private Sub buttonCollapseAllButThis_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If tableView1.FocusedRowHandle >= 0 Then
    End If
    For i As Integer = 0 To gridControl1.VisibleRowCount - 1
        Dim rowHandle As Integer = gridControl1.GetRowHandleByVisibleIndex(i)
        If rowHandle <> tableView1.FocusedRowHandle Then
        End If
    Next i
End Sub
See Also