Back to Devexpress

How to: Expand/Collapse a Group Row When It Receives Focus

windowsforms-3050-controls-and-libraries-data-grid-examples-navigation-and-selection-how-to-expand-collapse-a-group-row-when-it-receives-focus.md

latest1.2 KB
Original Source

How to: Expand/Collapse a Group Row When It Receives Focus

  • Nov 13, 2018

This example expands a collapsed group row and vice versa when this row receives focus.

csharp
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;

private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) {
     GridView view = sender as GridView;
     if (view == null) return;
     if (view.IsGroupRow(e.FocusedRowHandle)) {
        bool expanded = view.GetRowExpanded(e.FocusedRowHandle);
        view.SetRowExpanded(e.FocusedRowHandle, !expanded);
     }
}
vb
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base

Private Sub GridView1_FocusedRowChanged(ByVal sender As System.Object, _
  ByVal e As FocusedRowChangedEventArgs) Handles GridView1.FocusedRowChanged
   Dim view As GridView = sender
   If view Is Nothing Then
       Return
   End If
   If view.IsGroupRow(e.FocusedRowHandle) Then
      Dim expanded As Boolean = view.GetRowExpanded(e.FocusedRowHandle)
      view.SetRowExpanded(e.FocusedRowHandle, Not expanded)
   End If
End Sub