KB Article A369
Visible to All Users

How can I Auto-Expand all Sub-Detail Views when Expanding my Root Master Rows

Description:
How can I Auto-Expand all Sub-Detail Views when Expanding my Root Master Rows

Answer:
The best way to implement such a capability is to write a handler for the MasterRowExpanded event of your root Grid view. Simply retrieve the Detail view object of the current Master row, traverse all its rows and call the SetMasterRowExpanded method to accomplish the auto-expand.
Here is some sample code:

C#
using DevExpress.XtraGrid.Views.Grid; ... private void gridView_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e) { GridView masterView = sender as GridView; GridView detailView = masterView.GetDetailView(e.RowHandle) as GridView; masterView.BeginUpdate(); for(int i = 0; i < detailView.DataRowCount; i++) detailView.SetMasterRowExpanded(i, true); masterView.EndUpdate();
Visual Basic
Imports DevExpress.XtraGrid.Views.Grid ... Private Sub GridView1_MasterRowExpanded(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs) Handles GridView1.MasterRowExpanded Dim masterView As GridView = CType(sender, GridView) Dim detailView As GridView = CType(masterView.GetDetailView(e.RowHandle), GridView) masterView.BeginUpdate() Dim i As Integer For i = 0 To detailView.DataRowCount - 1 detailView.SetMasterRowExpanded(i, True) Next i masterView.EndUpdate() End Sub

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.