Back to Devexpress

TcxGridTableView.CreateColumn Method

vcl-cxgridtableview-dot-tcxgridtableview-ffa51dfe.md

latest3.2 KB
Original Source

TcxGridTableView.CreateColumn Method

Creates a new column and adds it to the Columns collection.

Declaration

delphi
function CreateColumn: TcxGridColumn;

Returns

TypeDescription
TcxGridColumn

The created column.

|

Remarks

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

Code Example: Create an Unbound Column

The following code example creates an unbound Table View column, assigns an in-place spin editor to it, and limits the editor’s input value range:

delphi
uses cxSpinEdit;
// ...
var
  AColumn: TcxGridColumn;
  ASpinEditProperties: TcxSpinEditProperties;
begin
  AColumn := cxGrid1TableView1.CreateColumn; // Creates a new unbound column
  AColumn.DataBinding.ValueType := 'Currency'; // Changes the column value type to "Currency"
  AColumn.PropertiesClass := TcxSpinEditProperties; // Assigns an in-place spin editor
  ASpinEditProperties := AColumn.Properties as TcxSpinEditProperties;
  ASpinEditProperties.MinValue := 0; // Sets the minimum edit value
  ASpinEditProperties.MaxValue := 1000; // Sets the maximum edit value
  ASpinEditProperties.Circular := True; // Loops value changes within the defined range
end;
cpp
#include "cxSpinEdit.hpp"
// ...
  TcxGridColumn *AColumn;
  TcxSpinEditProperties *ASpinEditProperties;
  // ...
  AColumn = cxGrid1TableView1->CreateColumn(); // Creates a new unbound column
  AColumn->DataBinding->ValueType = "Currency"; // Changes the column value type to "Currency"
  AColumn->PropertiesClass = __classid(TcxSpinEditProperties); // Assigns an in-place spin editor
  ASpinEditProperties = dynamic_cast<TcxSpinEditProperties*>(AColumn->Properties);
  ASpinEditProperties->MinValue = 0; // Sets the minimum edit value
  ASpinEditProperties->MaxValue = 1000; // Sets the maximum edit value
  ASpinEditProperties->Circular = true; // Loops value changes within the defined range

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
cxGrid1TableView1Column1.Free;
cpp
delete cxGrid1TableView1Column1;

See Also

TcxGridDBTableView.CreateColumn Function

TcxGridServerModeTableView.CreateColumn Function

TcxGridTableView Class

TcxGridTableView Members

cxGridTableView Unit