What Can Cause Properties, Methods, and Events of a Detail View to Fail?
- 2 minutes to read
When using Grid Control in a master-detail mode, you may need to refer to rows within detail Views. However, if you refer to rows via detail pattern Views, you will get undesired results. For instance, reading the ColumnView.FocusedRowHandle property for a detail pattern View will always return the GridControl.InvalidRowHandle value (-999999).
int row = gridView2.FocusedRowHandle; // where gridView2 is a detail pattern View Console.WriteLine(row); // row is always -999999
A common mistake when performing data specific operations in a master-detail mode on detail views (deleting and obtaining records, collapsing/expanding groups and master rows, etc.) is using pattern views that are created at design time and used as sublevels of GridControl. Pattern views don't contain any data and they are never displayed on screen. Pattern views only serve as templates, i.e. they provide layout settings for representing data displayed by real detail views (clones). You can get detailed information on pattern and clone views in Master-Detail Relationships. There are several ways to access a real Grid View with which an end-user interacts at runtime:
- GridControl.MainView - returns the top most view in a grid;
- GridControl.FocusedView - returns the focused view;
- the sender parameter of view specific events;
- GridView.GetDetailView - returns a detail view for a specific master row.
After the required view is obtained, you can get the currently focused row via the view's ColumnView.FocusedRowHandle property or use any other property or method of the detail view.
using DevExpress.XtraGrid.Views.Base; // Obtain the focused row of the currently focused view int row = (gridControl1.FocusedView as ColumnView).FocusedRowHandle; // Obtain the focused view of a specific detail view // gridView1 corresponds to GridControl.MainView ColumnView detailView = gridView1.GetDetailView(0, 0) as ColumnView; row = detailView.FocusedRowHandle;