vcl-cxgridlevel-d98f0064.md
A grid level.
TcxGridLevel = class(
TcxComponent,
IdxScaleFactor
)
Grid levels are designed to arrange and display data in the TcxGrid control. To display data in a grid View, associate the View with an existing grid level.
The list below outlines key members of the TcxGridLevel class. These members allow you to configure the grid level hierarchy and customize related settings.
ImageIndexAllows you to associate an icon with the grid level. The specified index specifies an icon within an image list assigned to the LevelTabs.Images property of the parent TcxGrid control.MaxDetailHeightAllows you to limit the maximum height for an associated grid detail View.Options | StylesAllow you to customize appearance for detail grid Views and corresponding tabs in master-detail relationships.
AddAdds a new nesting grid level to the collection accessible through the Items property.CountReturns the number of nested grid levels accessible through the Items property.IsMasterIdentifies if the grid level has visible nested levels.IsRootIdentifies if the grid level is a root for the parent TcxGrid control.ItemsProvides access to the collection of nested grid levels.ParentProvides access to the parent grid level.VisibleCountReturns the number of visible nested grid levels accessible through the VisibleItems property.VisibleItemsProvides access to the collection of visible nested grid levels.
ActiveSpecifies if the grid level is active. This property always returns True for a root grid level.ActuallyVisibleIdentifies if the grid level is visible at the current hierarchy level.ControlProvides access to the parent TcxGrid control.GridView
Specifies the associated grid View.
Note
You need to associate a grid View with the grid level to display data.
MakeVisibleDisplays the grid level (expands all parent levels).VisibleSpecifies if the grid level is visible.
The code example in this section creates an unbound grid Table View (TcxGridTableView) with three columns and populates them. To display data in the TcxGrid control, the code example also creates a root grid level and associates it with the created grid View.
uses
cxGrid, // Declares the TcxGrid control
cxGridLevel, // Declares the TcxGridLevel class
cxGridTableView, // Declares TcxGridTableView and TcxGridColumn classes
cxTextEdit, // Declares the TcxTextEditProperties class
cxSpinEdit; // Declares the TcxSpinEditProperties class
// ...
var
AGrid: TcxGrid;
AGridLevel: TcxGridLevel;
ATableView: TcxGridTableView;
AColumn: TcxGridColumn;
begin
AGrid := TcxGrid.Create(Self); // Creates a TcxGrid control
AGrid.Parent := Self; // Associates the TcxGrid control with the application form
AGrid.Align := alClient;
AGridLevel := AGrid.Levels.Add; // Creates a root grid level
// Create and configure a Table View
ATableView := AGrid.CreateView(TcxGridTableView) as TcxGridTableView;
AGridLevel.GridView := ATableView; // Associates the Table View with the root grid level
// Configure and populate the created Table View
ATableView.BeginUpdate; // Initiates the following batch operation
try
AColumn := ATableView.CreateColumn; // Creates the first column
AColumn.Caption := 'Planet Name';
AColumn.PropertiesClass := TcxTextEditProperties; // Assigns a single-line text editor
(AColumn.Properties as TcxTextEditProperties).ReadOnly := True; // Enables read-only mode
(AColumn.Properties as TcxTextEditProperties).HideSelection := True; // Disables selection
AColumn := ATableView.CreateColumn; // Creates the second column
AColumn.PropertiesClass := TcxSpinEditProperties; // Assigns a spin editor
(AColumn.Properties as TcxSpinEditProperties).Increment := 10;
AColumn.Caption := 'Distance';
AColumn := ATableView.CreateColumn; // Creates the third column
AColumn.Caption := 'Period (days)';
ATableView.DataController.RecordCount := 2; // Creates two empty records in a data controller
// Populate the first record
ATableView.DataController.Values[0, 0] := 'Mercury';
ATableView.DataController.Values[0, 1] := 57910;
ATableView.DataController.Values[0, 2] := 87.97;
// Populate the second record
ATableView.DataController.Values[1, 0] := 'Earth';
ATableView.DataController.Values[1, 1] := 149600;
ATableView.DataController.Values[1, 2] := 365.26;
finally
ATableView.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
ATableView.ApplyBestFit; // Adjusts column width to fit captions and content (once data is displayed)
end;
end;
#include "cxGrid.hpp" // Declares the TcxGrid control
#include "cxGridLevel.hpp" // Declares the TcxGridLevel class
#include "cxGridTableView.hpp" // Declares TcxGridTableView and TcxGridColumn classes
#include "cxTextEdit.hpp" // Declares the TcxTextEditProperties class
#include "cxSpinEdit.hpp" // Declares the TcxSpinEditProperties class
// Add the following linker directive to the corresponding CPP source file:
#pragma link "cxGrid" // Required to use cxGrid.hpp declarations
#pragma link "cxGridLevel" // Required to use cxGridLevel.hpp declarations
#pragma link "cxGridTableView" // Required to use cxGridTableView.hpp declarations
#pragma link "cxTextEdit" // Required to use cxTextEdit.hpp declarations
#pragma link "cxSpinEdit" // Required to use cxSpinEdit.hpp declarations
// ...
TcxGrid *AGrid;
TcxGridLevel *AGridLevel;
TcxGridTableView *ATableView;
TcxGridColumn *AColumn;
// ...
AGrid = new TcxGrid(this); // Creates a TcxGrid control
AGrid->Parent = this; // Associates the TcxGrid control with the application form
AGrid->Align = alClient;
AGridLevel = AGrid->Levels->Add(); // Creates a root grid level
// Create and configure an unbound Table View
ATableView = dynamic_cast<TcxGridTableView*>(AGrid->CreateView(__classid(TcxGridTableView)));
AGridLevel->GridView = ATableView; // Associates the Table View with the root grid level
// Configure and populate the created Table View
ATableView->BeginUpdate(); // Initiates the following batch operation
try
{
AColumn = ATableView.CreateColumn(); // Creates the first column
AColumn->Caption = "Planet Name";
AColumn->PropertiesClass = __classid(TcxTextEditProperties); // Assigns a single-line text editor
dynamic_cast<TcxTextEditProperties*>(AColumn->Properties)->ReadOnly = true; // Enables read-only mode
dynamic_cast<TcxTextEditProperties*>(AColumn->Properties)->HideSelection = true; // Disables selection
AColumn = ATableView->CreateColumn(); // Creates the second column
AColumn->PropertiesClass = __classid(TcxSpinEditProperties); // Assigns a spin editor
dynamic_cast<TcxSpinEditProperties*>(AColumn->Properties)->Increment = 10;
AColumn->Caption = "Distance";
AColumn = ATableView->CreateColumn(); // Creates the third column
AColumn->Caption = "Period (days)";
ATableView->DataController->RecordCount = 2; // Creates two empty records in a data controller
// Populate the first record
ATableView->DataController->Values[0][0] = "Mercury";
ATableView->DataController->Values[0][1] = 57910;
ATableView->DataController->Values[0][2] = 87.97f;
// Populate the second record
ATableView->DataController->Values[1][0] = "Earth";
ATableView->DataController->Values[1][1] := 149600;
ATableView->DataController->Values[1][2] := 365.26f;
}
__finally
{
ATableView->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
ATableView->ApplyBestFit(); // Adjusts column width to fit captions and content (once data is displayed)
}
The following public API members reference a TcxGridLevel object:
TcxGridLevel.AddAdds a new child (detail) level.TcxGridLevel.ItemsSpecifies the collection of child (detail) levels for the current grid level.TcxGridLevel.VisibleItemsSpecifies the collection of child (detail) levels which can be displayed.TcxCustomGrid.ActiveLevelSpecifies the root grid level which is currently active.TcxCustomGrid.LevelsProvides access to the collection of root grid levels within a grid control.
TObject TPersistent TComponent TcxCustomComponent TcxComponent TcxGridLevel
See Also