Back to Devexpress

TcxGridDBColumn Class

vcl-cxgriddbtableview-1e7d7ee8.md

latest18.1 KB
Original Source

TcxGridDBColumn Class

A column in a data-aware grid Table View.

Declaration

delphi
TcxGridDBColumn = class(
    TcxGridColumn
)

Remarks

A column in a data-aware Table View is designed to display values from a dataset field. Use the DataBinding property to bind a data-aware column to data.

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.

Default In-Place Editor and Data Types

When PropertiesClassName and PropertiesClass properties are unspecified, the data type of the underlying dataset field determines the active in-place editor according to the following table:

Dataset Field TypeDefault In-Place EditorDescription
ftBooleanTcxCheckBoxA check box editor with support for three states.
ftCurrency, ftBCD, and ftFMTBcdTcxCurrencyEditA numeric editor for currency values.
ftDate and ftDateTimeTcxDateEditA date editor with a drop-down calendar.
ftTimeTcxTimeEditA spin editor for time values.
ftBytes, ftVarBytes, ftBlob, ftFmtMemo, ftParadoxOle, ftDBaseOle, and ftTypedBinaryTcxBlobEditA Binary Large Object (BLOB) editor.
ftMemoTcxMemoA multi-line editor for plain text.
ftGraphicTcxImageAn editor designed to display images.
All other typesTcxMaskEditA single-line text editor with support for input masks.

Main API Members

The list below outlines key members of the TcxGridDBColumn class. These members allow you to configure columns in data-aware Table grid Views.

General Appearance Settings

ApplyBestFit | BestFitMaxWidthAllow you to adjust the column width to display content in full and limit the maximum column width in this mode.Caption | AlternateCaptionSpecify main and alternative captions for the column. An alternative column caption can replace the main caption in customization dialogs, filter panels, etc.HeaderGlyph | HeaderImageIndexAllow you to assign a glyph to the column header.OnCustomDrawCellAllows you to override or complement column draw routines.OnGetDisplayText | OnGetFilterDisplayTextAllow you to customize display text and column captions displayed in a filter drop-down window.OnGetFilterImages | OnGetFilterValuesAllow you to customize the column’s filter drop-down window.StylesAllows you to customize the appearance of different column elements.

Column Layout Settings

FooterAlignmentHorzAllows you to position column footer cells.HeaderAlignmentHorz | HeaderAlignmentVertPosition the column header horizontally and vertically.HeaderGlyphAlignmentHorz | HeaderGlyphAlignmentVertSpecify the glyph position within the column header.LayoutItem | RowLayoutItemAllow you to configure the column in a custom row layout.MinWidthSpecifies the minimum column width, in pixels.

In-Place Editor Settings

AIProvides access to AI-powered functionality settings.EditingSpecifies if the assigned in-place cell editor is active.OnGetPropertiesAllows you to display different in-place editors for different records or customize editor settings based on custom conditions.OnGetPropertiesForEditAllows you to change the assigned in-place editor and customize its settings when a user invokes the editor.PropertiesProvides access to the settings of the assigned in-place editor.PropertiesClassSpecifies the active in-place editor class. At design time, you can use the Properties node in the Object Inspector to assign an in-place editor to the column and configure the editor.RepositoryItem

Allows you to associate the column with a repository item that defines the required in-place editor and its settings.

Tip

Repository items are particularly useful if you need to share in-place editor settings between multiple grid View items or customize editor settings in OnGetProperties and OnGetPropertiesForEdit event handlers.

Data Management

DataBindingProvides access to data binding settings.GroupIndexAllows you to group columns in the parent grid View by the current column.SortIndex | SortOrderAllow you to sort data in the parent grid View against the current column.

Grid View-Related API Members

IsBottom | IsLeft | IsMostBottom | IsMostLeft | IsMostRight | IsRight | IsTopAllow you to identify the column’s position within the parent grid View.FixedKindAllows you to fix the column or dock it to the left when users scroll the parent grid View to the right.FocusedSpecifies if the column has focus.IndexDefines the column position in its parent grid View.IsFirst | IsLastIdentify if the column is the first or last in the parent grid View’s collection of visible columns.IsPreviewAllows you to identify if the column has a preview section.MakeVisibleScrolls the parent grid View to display the current column.SelectedIdentifies if the column is selected.SummaryProvides access to column summary settings.VisibleForEditForm | VisibleForRowLayoutSpecify if the column is visible in an in-place Edit Form and the custom row layout.

General-Purpose API Members

Automation

Provides access to UI Automation and accessibility-related settings.[1]

Tip

Use Automation.Name, Automation.Description, and other API members to specify information visible to third-party assistive tools as UIA node properties.

EditableAllows you to identify if the column is editable.GridViewProvides access to the parent grid View.OptionsAllows you to configure general column settings.RestoreDefaultsRestores the default values of column type-specific settings, such as Caption and Width.ShowExpressionEditorInvokes the Expression Editor dialog.VisibleSpecifies if the column is visible.

Code Example: Create a Data-Aware Column

The following code example creates a data-aware column, associates it with a field in the dataset bound to the parent grid Table View, sorts data against the created column in descending order, sets a single-line text editor as the column’s in-place editor, and customizes editor settings:

delphi
uses cxTextEdit;
// ...
var
  AColumn: TcxGridDBColumn;
  ATextEditProperties: TcxTextEditProperties;
begin
  AColumn := cxGrid1DBTableView1.CreateColumn; // Creates a new data-aware column
  AColumn.DataBinding.FieldName := 'ContactName'; // Binds the created column to the "ContactName" field
  cxGrid1DBTableView1.DataController.ClearSorting(False); // Clears the current sorting
  AColumn.SortOrder := soDescending; // Sorts data against the created column in descending order
  AColumn.PropertiesClass := TcxTextEditProperties; // Assigns an in-place single-line text editor
  ATextEditProperties := AColumn.Properties as TcxTextEditProperties;
  ATextEditProperties.BeginUpdate; // Initiates the following batch change
  try
    ATextEditProperties.Nullstring := 'Add a contact name'; // Prompts users to enter a contact name
    ATextEditProperties.UseNullString := True; // Displays the defined text hint in an empty editor
    ATextEditProperties.MaxLength := 30; // Limits the maximum contact name length
    ATextEditProperties.Alignment.Horz := taCenter; // Centers column content
  finally
    ATextEditProperties.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
end;
cpp
#include "cxTextEdit.hpp"
// ...
  TcxGridDBColumn *AColumn;
  TcxTextEditProperties *ATextEditProperties;
  // ...
  AColumn = cxGrid1DBTableView1->CreateColumn(); // Creates a new data-aware column
  AColumn->DataBinding->FieldName = "ContactName"; // Binds the created column to the "ContactName" field
  cxGrid1DBTableView1->DataController->ClearSorting(false); // Clears the current sorting
  AColumn->SortOrder = soDescending; // Sorts data against the created column in descending order
  AColumn->PropertiesClass = __classid(TcxTextEditProperties); // Assigns an in-place single-line text editor
  ATextEditProperties = dynamic_cast<TcxTextEditProperties*>(AColumn->Properties);
  ATextEditProperties->BeginUpdate();
  try
  {
    ATextEditProperties->Nullstring = "Add a contact name"; // Prompts users to enter a contact name
    ATextEditProperties->UseNullString = true; // Disables the defined hint text in an empty editor
    ATextEditProperties->MaxLength = 30; // Limits the maximum contact name length
    ATextEditProperties->Alignment->Horz = taCenter; // Centers column content
  }
  __finally
  {
    ATextEditProperties->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

Grid Column Deletion

To delete a grid column, release it directly in code (call the Free procedure in Delphi or use the delete keyword in C++Builder):

delphi
cxGrid1DBTableView1Column1.Free;
cpp
delete cxGrid1DBTableView1Column1;

Direct TcxGridDBColumn Class References

The following public API members reference a TcxGridDBColumn object:

TcxGridDBTableView.ColumnsProvides indexed access to the collection of the View’s columns.TcxGridDBTableView.CreateColumnCreates a column and adds it to the Columns collection.TcxGridDBTableView.GetColumnByFieldNameLocates the column displaying a particular field’s values.

Other Grid Column Classes

Unbound

TcxGridBandedColumnA column in an unbound Banded Table View.TcxGridColumnA column in an unbound grid Table View.

Data-Aware

TcxGridDBBandedColumnA column in a data-aware Banded Table grid View.

Server Mode

TcxGridServerModeColumnA column in a Server Mode grid Table View.TcxGridServerModeBandedColumnA column of a Banded Table View in Server Mode.

To see the Table grid View in action, run the Grid and Data Editors demo in the VCL Demo Center installed with compiled DevExpress demos. Click the Fixed Columns item in the side bar to the left.

Download: Compiled VCL Demos

Tip

Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users ( default ). You can find all project and source code files for the Data Grid demo in the following folder:

%Public%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressQuantumGrid

Inheritance

TObject TPersistent TComponent TcxCustomComponent TcxComponent TcxCustomGridTableItem TcxCustomGridColumn TcxGridColumn TcxGridDBColumn

Footnotes

  1. In 25.2, only simple grid Table Views (Unbound, Data-Aware, and Server Mode) support UI Automation functionality if the dxUIAutomationEnabled property is set to True.

See Also

TcxGridDBTableView Class

TcxGridItemDBDataBinding.FieldName Property

TcxGridDBColumn Members

cxGridDBTableView Unit