Description:
How do I customize the grid detailed view?
Answer:
You can do this at design time as well as at runtime.
AT DESIGN TIME
When an XtraGrid control is placed on a form, the Level Designer is displayed in the bottom right corner of the control. Initially, the level designer provides access to the automatically created View that represents the grid's main View (GridControl.MainView):
If the grid is bound to a data source that contains master-detail relationships, the information about master-detail relationships can be retrieved from the bound data source by clicking the Retrieve Details button. As a result, new levels, whose names match the name of the relationship to which the level corresponds, are created. A level in XtraGrid is simply an association of a master-detail relationship. The View used to represent this relationship (the level name) should match the name of the master-detail relationship. Select the required view in order to customize it - show/hide columns, define grouping, sorting, and summaries, apply styles, etc.
If it is impossible to retrieve the data structure, you can create and customize all levels and views manually using the Level Designer:
- Create a new level and assign a view to it. When adding a new level node to the GridLevelNode.Nodes collection, its GridLevelNode.RelationName should match the relationship's name.
- Create required columns. The column's FieldName should match the source's field name. See the training video from DevExpress StartHere. You can find it in Visual Studio: DevExpress --> StartHere --> WinForms --> DataGrid --> MasterDetailRelationships
AT RUNTIME
To customize each detail view, handle the GridControl.ViewRegistered event in order to perform all the necessary customizations. Use the e.View parameter to assess the currently processed view. Or, handle the GridView.MasterRowExpanded event. Obtain the detail view using the GridView.GetDetailedView method. Review the A2158 to learn how to obtain the detailed view's properties. See the GridRunTimeUsing tutorial shipped with DXperience (it can be found at "C:\Users\Public\Documents\DevExpress Demos 13.2\Components\WinForms\CS\GridTutorials\GridRunTimeUsing")
For more information refer to the following articles:
Binding to Data
Binding to Data Specifics
Views and Levels View Specifics
Detail Pattern and Clone Views
Master-Detail: Using Events
Online video:
WinForms Grid: Master-Detail Relationships