Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Collapse]Master-Detail Relationships
     Master-Detail Overview
    [Expand]Binding to Data Specifics
    [Collapse]View Specifics
      Detail Pattern and Clone Views
      Specify Views to Represent Detail Data
      Master and Detail View Vertical Scrolling (Embedded Detail Mode)
      Detail View Size
      Synchronizing Detail Views
      Zooming Views
      Using Detail ToolTips
      Using Detail Tabs
    [Expand]Row Specifics
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Detail Pattern and Clone Views

In master-detail mode, an end-user operates with master and detail data, displayed within master and detail Views. Master rows in a master View can be expanded to show detail Views with corresponding detail data. When multiple master rows within the same master View are expanded, this opens detail Views that typically look alike. These detail Views usually have the same set and layout of columns, the same sort, group and filter settings, etc. The reason for the similarity is that detail Views shown at runtime are all Clones of an abstract detail View, called a Detail Pattern View. Detail Pattern Views never appear at runtime, because they are only used for creating Detail Clones.

Note

When pixel-based vertical row scrolling is enabled, the Master-Detail Mode is forcibly disabled. See GridOptionsBehavior.AllowPixelScrolling, to learn more.

Expanded Detail Pattern Views vs. Detail Clone Views

Let's consider a simple example in which a Suppliers table is linked to a Products detail table by a one-to-many relationship called "SuppliersProducts". Here is the data scheme of the data set containing these tables:


Image 1. A sample relationship between two data tables.

When displaying the master and detail tables in the Grid control, you need to specify master and detail Views that will represent the data from these tables. This can easily be performed at design time via the Grid's Level Designer (the box displayed at the bottom-right corner of the Grid). The Level Designer allows you to specify a View to display the master data table, and associate detail Pattern Views with master-detail relationships (thus associating them with detail tables). The Level Designer reflects the relationship for the above dataset scheme as follows (assuming that the Grid is bound to the Suppliers master table):


Image 2. The grid's Level Designer.

In the diagram above:

  1. The Level Designer always contains the (MainView) level, even when Master-Detail mode is not used.
  2. gridView1 is assigned to the (MainView) level, and is used to represent the top-level record set from the bound data source. The same View is specified by the GridControl.MainView property.
  3. "SuppliersProducts" is the name of a detail level. This name must match the name of the relationship in the data source.
  4. gridView2 is the Detail Pattern View assigned to the "SuppliersProducts" level. Thus, it is associated with the "SuppliersProducts" relationship. Each time an end-user expands a master row in gridView1 to show the corresponding detail data, a Clone of gridView2 is created and displayed onscreen.

The following is the result of expanding two master rows at runtime. Notice that the tabs display the name of the detail level ("SuppliersProducts"):


Image 3. A grid displaying details corresponding to one master-detail relationship at runtime.

When detail data corresponding to a particular relationship is about to be displayed, the grid does the following:

  1. Identifies the required Detail Pattern View.
  2. Creates a Clone by copying the Pattern View's settings and event handlers to the Clone.
  3. Displays the Clone below the expanded master row.

Expanded Accessing Detail Clone and Pattern Views

End-users can access and interact with Detail Clone Views at runtime when master rows are expanded. An end-user, for example, can open, collapse, focus, or change the cell values within a Detail Clone View.

Note

You cannot access or customize a Detail Clone View at design time. Instead, customize the Detail Pattern View, which serves as the template for creating Clones.

Because Detail Pattern Views are never displayed onscreen, they do not contain data and their BaseView.RowCount properties return 0. As a result, it is not possible to call data-related or focus-related methods on a Detail Pattern View. These methods must only be invoked for Detail Clone Views.

At runtime, Detail Clone Views can be accessed as follows:

At runtime, you can get the Pattern View that was used to create the current Detail Clone via the BaseView.SourceView property. The BaseView.ParentView property allows you to get the master View for the Clone.

Expanded Synchronizing Details

By default, Detail Clones for all rows are synchronized. That is, changing the appearance settings and data layout of one Detail Clone affects all other Clones, as well as the Pattern View. Similarly, changing the layout of the Pattern View affects the appearance of all opened Clones, as well as all Clones created thereafter. To specify whether or not Detail Clones are synchronized, use the BaseView.SynchronizeClones property. For more information on synchronization, see the Synchronizing Detail Views document.

Expanded Assigning Detail Pattern Views to Master-Detail Relationships

For each master-detail relationship, you must provide a Pattern View whose settings will be used to create corresponding Detail Clones. This can be done using the following methods:

  1. At design time, via the Grid's Level Designer. See the Level Designer topic to learn more.
  2. Dynamically, via the GridView.MasterRowGetLevelDefaultView event. See the Master-Detail: Using Events topic for more information.
  3. In code, via the GridControl.LevelTree property. The use of this property is explained below.

At runtime, you can assign Pattern Views to master-detail relationships using the GridControl.LevelTree property. This represents a tree-like structure of GridLevelNode objects. Tree nodes (except for the root node) represent specific master-detail relationships, and each node provides the following two properties:

The links between nodes within the GridControl.LevelTree should reflect the hierarchy of the master-detail relationships in the bound data set. Thus, to provide a Pattern View for a specific relationship, a node must be added to the tree at the same nesting level as the nesting level of the relationship in the data set. Moreover, the node's GridLevelNode.RelationName property must be set to the name of the relationship so that the grid can locate the required node when it searches for a Pattern View.

Consider the following dataset scheme that shows four tables linked by three one-to-many relationships.


Image 4. Sample relationships between four data tables.

To correspond to this scheme, the structure of nodes in the LevelTree must be as follows:


Image 5. The structure of nodes in the LevelTree.

Here you can see how master-detail relationships are linked to Detail Pattern Views:
  • The root node is associated with gridView1. This is the top-level View in the Grid control. The root node always refers to the same value as the GridControl.MainView property.
  • The "SuppliersProducts" relationship is associated with gridView2.
  • The "Suppliers_CategoryProducts" relationship is associated with cardView1.
  • The "ProductsOrder Details" relationship is not associated with any View. For such nodes, the Detail Pattern View is the same as the parent node's Pattern View. In this example, gridView2 will be associated with the "ProductsOrder Details" relationship.

The following image shows a Grid control that is bound to the "Suppliers" table and whose LevelTree property is set according to the scheme in Image 5:


Image 6. A grid control displaying detail data corresponding to three master-detail relationships at runtime.

Note

The Pattern View that represents a relationship that is not referenced by the GridControl.LevelTree is determined as follows. The grid calculates the node that represents the parent relationship for the required relationship, and uses its associated View as a Pattern View for the required relationship.

Also note that relationships that are not referenced by the GridControl.LevelTree are displayed by the grid only if the GridControl.ShowOnlyPredefinedDetails property is set to false (the default value).

The GridControl.ShowOnlyPredefinedDetails property allows you to control which master-detail relationships can be displayed in the grid. This property is set to false by default, and Grid Control fetches and displays all master-detail relationships in the data source. If the GridControl.ShowOnlyPredefinedDetails property is set to true, the grid will only display the relationships that are referred to by the GridControl.LevelTree. Other relationships will not be displayed.

Expanded Example

The following sample code shows how to assign Views to the three master-detail relationships shown in Image 5. It is assumed that the GridControl.LevelTree does not contain any nodes for these relationships when the code is run.

Expanded Relation Names

Master-detail relationships in Grid Control are identified by names. The name of the relationship is used to get the default Pattern View from the GridControl.LevelTree, which will provide the settings for creating Detail Clones. If the GridControl.LevelTree does not contain an entry for the specified name and the GridControl.ShowOnlyPredefinedDetails property is set to false, the master View for the current detail will be used as the Pattern.

You can provide relationship names in the following ways:

Note that in some situations you may want to supply Pattern Views explicitly (not based on the relationship's name). In this case, handle the GridView.MasterRowGetLevelDefaultView event. The Pattern View assigned via this event will override the default Pattern View.

Expanded Example

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3861.

The following code demonstrates how to use the GridView.MasterRowGetRelationName event to provide a custom Pattern View for the first detail of the first master row. For other details, the default Pattern View is used.

The following image shows the result:

For information on implementing master-detail relationships for bound and unbound data, see the Master-Detail Overview topic.

Expanded See Also

How would you rate this topic?​​​​​​​