Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TcxGridDBTableView.CreateColumn Method

Creates a column and adds it to the Columns collection.

#Declaration

Delphi
function CreateColumn: TcxGridDBColumn;

#Returns

Type Description
TcxGridDBColumn

The created column.

#Remarks

Call the CreateColumn function to create a new data-aware column. The Columns property provides indexed access to all columns in the data-aware Table View.

#Code Example: Create and Configure 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:

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;

#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):

  cxGrid1DBTableView1Column1.Free;
See Also