Skip to main content

What Can Cause Properties, Methods, and Events of a Detail View to Fail?

  • 2 minutes to read

See also: DevExpress WinForms Troubleshooting - Grid Control

Issue Description

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

Solution

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:

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;
See Also