Back to Devexpress

TcxGridTableView Class

vcl-cxgridtableview.md

latest19.6 KB
Original Source

TcxGridTableView Class

An unbound Table View in the VCL Data Grid.

Declaration

delphi
TcxGridTableView = class(
    TcxCustomGridTableView,
    IdxLayoutContainerOwner
)

Remarks

The TcxGridTableView class implements a simple table designed to display data of the same type in corresponding columns.

In-Place Editors

A column can use any unbound editor shipped with the ExpressEditors Library as an in-place editor for cell edit operations. An in-place editor instance exists (and, therefore, consumes memory and other system resources, such as a WinAPI handle) only when a column cell is being edited. Otherwise, the column displays a static editor image for resource usage optimization.

To switch between available editors, you can use the PropertiesClassName or PropertiesClass property. Use the Properties property to configure the in-place editor associated with the column.

Sort Data

The View allows users to sort data in ascending or descending order.

Users can sort data by the following:

You can also sort data at design time and runtime.

Group Data

The View allows users to drag column headers to the Group By box to group data. You can combine any number of columns in data groups.

Filter

The View uses a data controller to filter data. When a user creates new filter conditions, the data controller retrieves only those data rows that meet these conditions. The View displays active filter criteria in the filter panel.

A user can create filter conditions in any of the following ways:

The View has the Find Panel that allows users to type search requests and highlight results. You can switch the panel between search and data filter processing modes.

The panel also supports extended syntax that allows a user to input compound requests.

Conditional Formatting

You can create rules to apply custom formatting to data rows whose content meets these rules.

Summaries

Summaries allow a user to calculate totals against all records or a group of records.

The View can display the Data Navigator pane that allows users to navigate through data rows, manage records, and filter data.

Main API Members

The list below outlines key members of the TcxGridTableView class. These members allow you to configure unbound grid Table Views.

General Appearance Settings

OptionsViewProvides access to general appearance settings.RowLayoutProvides access to row layout settings.PreviewAllows you to display and configure a preview section in the grid Table View.StylesAllows you to apply styles to the grid Table View.

General Behavior and User Interaction Settings

AutomationProvides access to UI Automation and accessibility-related settings.[1]OptionsBehaviorProvides access to general behavior settings.OptionsCustomizeAllows you to specify table layout customization options available to users.OptionsSelectionProvides access to all selection-related settings.

Column Management

ColumnCountReturns the number of columns accessible through the Columns property.ColumnsProvides indexed access to all columns in the grid Table View.CreateColumnCreates a new unbound column.GroupedColumnCountReturns the number of columns accessible through the GroupedColumns property.GroupedColumnsProvides indexed access to all grouped columns.VisibleColumnCountReturns the number of columns accessible through the VisibleColumns property.VisibleColumnCountByFixedKindReturns the number of fixed columns (by anchor mode).VisibleColumnsProvides indexed access to all visible columns in the grid Table View.

Data Management and Data-Related Options

DataController

Provides access to the data controller designed to store and manage data displayed in the grid Table View.

Tip

Use DataController.RecordCount and DataController.Values properties to populate the grid Table View in unbound data access mode as demonstrated in the code example below.

Data Shaping APIs

ConditionalFormattingAllows you to apply and manage conditional formatting rules.DateTimeHandlingProvides access to date/time value display and interpretation settings.FilteringProvides access to data filter settings.FilterRowAllows you to display and configure a filter row.OptionsDataProvides access to data-related grid Table View behavior settings. You can use these settings to specify data operations available to users (add, insert, delete records, etc.).SortedItemCountReturns the number of sorted columns accessible through the SortedItems property.SortedItemsProvides indexed access to all sorted columns.

Custom Draw Events

OnCustomDrawCellAllows you to override or complement built-in draw routines for data cells.OnCustomDrawColumnHeaderAllows you to override or complement built-in draw routines for column headers.OnCustomDrawFooterCellAllows you to override or complement built-in draw routines for footer cells.OnCustomDrawGroupCellAllows you to override or complement built-in draw routines for group row cells.OnCustomDrawGroupSummaryCellAllows you to override or complement built-in draw routines for group summary cells.OnCustomDrawIndicatorCellAllows you to override or complement built-in draw routines for indicator column cells.OnCustomDrawPartBackgroundAllows you to override or complement built-in background draw routines.

User Interaction Events

OnColumnHeaderClickAllows you to execute custom code in response to clicks on column headers.OnColumnPosChanged | OnColumnSizeChangedAllow you to respond to column position and size changes.OnGroupRowExpanded | OnGroupRowCollapsedAllow you to respond to group row expand and collapse operations.OnGroupRowExpanding | OnGroupRowCollapsingAllow you to prevent users from expanding or collapsing group rows.OnLeftPosChangedAllows you to track horizontal scrollbar movement.

General-Purpose API Members

ControllerProvides access to the grid Table View controller. You can use this property to execute commands available to users in the UI (search, edit operations, navigation, scrolling, etc.).ViewDataProvides access to all rows currently visible in the grid Table View client area.

Code Example: Create and Populate Unbound Grid Views

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.

delphi
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;
cpp
#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)
  }

Other Grid View Classes

Table Views

TcxGridDBTableViewA bound Table View in the VCL Data Grid.TcxGridServerModeTableViewThe Table View that provides support for server mode.

Banded Table Views

TcxGridBandedTableViewA View that groups columns into bands.TcxGridDBBandedTableViewA data-aware Banded Table View.TcxGridServerModeBandedTableViewThe Banded Table View that provides support for server mode.

Card Views

TcxGridCardViewA Card grid View.TcxGridDBCardViewRepresents a data-aware Card View.

Layout Views

TcxGridLayoutViewAn unbound Layout grid View.TcxGridDBLayoutViewA data-aware Layout View.

WinExplorer Views

TcxGridWinExplorerViewAn unbound WinExplorer View.TcxGridDBWinExplorerViewA data-aware WinExplorer View.

Implements

IdxLayoutContainerOwner

Inheritance

TObject TPersistent TComponent TcxCustomComponent TcxComponent TcxControlChildComponent TcxCustomGridView TcxCustomGridTableView TcxGridTableView

Footnotes

  1. Each column has its own Automation property.

See Also

Table View Tutorial

TcxGridTableView Members

cxGridTableView Unit