Grid Levels
- 4 minutes to read
The VCL Grid Control can arrange grid Views into multi-level hierarchical structures. This topic describes how you can manage grid Levels, associate them with grid Views, and customize grid Level settings.
Manage Grid Levels
A grid Level can nest other Levels, so you can build a tree-like Level hierarchy of any complexity. The grid control’s Levels property returns the root hierarchy Level that has no associated grid View and, therefore, is not used to display data. This Level only stores a collection of nested Levels and determines their appearance.
The root Level’s Add function allows you to create a grid Level at the top of the hierarchy as the root Level’s child. To create a grid Level at any position within the hierarchy, call the Add function of the target parent Level. To delete a grid Level, call its Free procedure.
At design time, you can use the Structure Navigator displayed at the bottom-right corner of the grid control to manage its Levels. The image below illustrates the Structure Navigator of a grid control when it is added to a form.
The Structure Navigator hides the root Level for your convenience because this Level is not used to display data. You can right-click the grid control’s label (cxGrid1
) and select Add Level in the context menu to create a grid Level at the top of the hierarchy.
To create a grid Level at any position within the hierarchy, right-click the target parent Level’s label (cxGrid1Level1
) and select AddLevel in its context menu.
The following image shows the resulting grid structure:
Specify Associated Grid Views
Each grid Level requires an associated grid View to shape and visualize data. You can specify associated Views and switch between them at any time. The image below shows the grid control whose grid Levels have associated Views. The grid Levels at the top hierarchy Level (cxGrid1Level1
and cxGrid1Level2
) display data from independent data sources.
The grid Level at a deeper hierarchy Level (cxGrid1Level3
) creates a master-detail relationship with its parent (cxGrid1Level1
) and displays details for it.
You can use the GridView property of a root Level child to associate it with a grid View. The method you use to specify a grid View for a detail grid Level depends on whether you want to apply this View and its settings to every detail created for this Level. The sections below describe each method in detail. Refer to the following topic for information on how the grid control implements these methods: Pattern and Clone Views.
Apply the Same View Settings to Details
This is the most common use case. You can assign a grid View to a detail Level’s GridView property to apply this View and its settings to each detail created for the Level. Do the following to create a grid View and assign it to a detail Level at design time:
- Right-click the detail Level’s label (
cxGrid1Level3
) in the Structure Navigator. - Click Create View in the context menu.
- Select a View type in the opened submenu.
The following image shows details that use the assigned View to display their data:
Apply Different View Settings to Details
You can assign a grid View to a detail Level’s GridView property and handle the Level’s OnGetGridView event to replace the assigned View in each detail.
You have the following options to create and customize Views before you pass them to an OnGetGridView event handler:
- Create Views within the grid control but do not associate them with grid Levels.
- Create standalone Views in the TcxGridViewRepository component.
Refer to the OnGetGridView event description for details on how to use these Views with the event.
Main Settings
The list below outlines key TcxGridLevel settings that allow you to customize the appearance of grid Levels and their details. You can use these settings to do the following:
- Specify the text displayed in the Level’s tabs (Caption).
- Customize the appearance of details and their tabs (Options and Styles).
- Switch the Level visibility (Visible).