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

GridControl.SetMasterRowExpanded(Int32, Boolean, DetailDescriptorBase) Method

Changes the expanded state for a specified master row and, optionally, shows a specified Detail.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v18.2.dll

Declaration

public void SetMasterRowExpanded(
    int rowHandle,
    bool expand,
    DetailDescriptorBase descriptor = null
)

Parameters

Name Type Description
rowHandle Int32

An integer value specifying the master row by its handle.

expand Boolean

true to expand the specified row; false to collapse it.

Optional Parameters

Name Type Default Description
descriptor DetailDescriptorBase *null*

Optional. A DetailDescriptorBase object specifying the detail section to be made visible when expanding a master row. If the specified object doesn’t represent a detail for the specified master row, then this parameter is ignored. The same happens if you pass null (Nothing in Visual Basic).

Remarks

Use this method to expand or collapse master rows from code or switch between visible details. This might become useful if you are providing your own control for master row management while disabling the TableView.ShowDetailButtons option. Another way to use this option is when implementing custom automated detail visibility management.

This method may not expand or collapse the master row if these actions are overridden in GridControl.MasterRowExpanding and/or GridControl.MasterRowCollapsing event handers.

To determine a master row’s expanded state and currently visible detail, use the GridControl.IsMasterRowExpanded and GridControl.GetVisibleDetailDescriptor (GridControl.GetVisibleDetail) methods.

Example

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.
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
        Return
    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)
        gridControl1.ExpandMasterRow(rowHandle)
    Next i
End Sub
Private Sub buttonCollapseAllButThis_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If tableView1.FocusedRowHandle >= 0 Then
        gridControl1.ExpandMasterRow(tableView1.FocusedRowHandle)
    End If
    For i As Integer = 0 To gridControl1.VisibleRowCount - 1
        Dim rowHandle As Integer = gridControl1.GetRowHandleByVisibleIndex(i)
        If rowHandle <> tableView1.FocusedRowHandle Then
            gridControl1.CollapseMasterRow(rowHandle)
        End If
    Next i
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetMasterRowExpanded(Int32, Boolean, DetailDescriptorBase) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also