method Columns.Add (ColumnCaption as String)
Adds a Column object to the collection and returns a reference to the newly created object.

TypeDescription
ColumnCaption as String A string expression that defines the column's caption
ReturnDescription
VariantA Column object that represents the newly created column.

By default, the control has no columns. Use Add method to add new columns to the control. If the control contains no columns, you cannot add new items to the control. Use the Remove method to remove a specific column. Each time when a column has been added to columns collection the control fires the AddColumn event. If the control's DataSource property points to an ADO recordset the user doesn't need to add columns to the control. Instead, the Add method can be used to add computed fields for instance. Use the AddItem, InsertItem, InsertControlItem, PutItems, DataSource properties to add new items to the control. Use the BeginUpdate and EndUpdate methods to prevent control from painting while adding columns or items. Use the Editor property to assign an editor to the cells in the column. Use the Def property to specify default setting for cells in the column. Use the FormatLevel property to display multiple levels in the column's header.

The following VB sample adds two new columns to the control:

With Grid1
    .Columns.Add "Column 1"
    With .Columns.Add("Column 2")
        With .Editor
            .EditType = CalculatorType
        End With
    End With
End With

The following C++ sample adds two new columns to the control:

#include "Column.h"
#include "Columns.h"
COleVariant vtMissing; V_VT( &vtMissing) = VT_ERROR;
CColumns columns = m_grid.GetColumns();
columns.Add( "Column 1" );
CColumn column( V_DISPATCH( &columns.Add( "Column 2" ) ) );
CEditor editor = column.GetEditor();
editor.SetEditType( 21 /*CalculatorType*/ );

The following VB.NET sample adds two new columns to the control:

With AxGrid1
    .Columns.Add("Column 1")
    Dim c As EXGRIDLib.Column = .Columns.Add("Column 2")
    With c.Editor
        .EditType = EXGRIDLib.EditTypeEnum.CalculatorType
    End With
End With

The following C# sample adds two new columns to the control:

EXGRIDLib.Column column = axGrid1.Columns.Add("Column 1") as EXGRIDLib.Column ;
column = axGrid1.Columns.Add("Column 2") as EXGRIDLib.Column;
column.Editor.EditType = EXGRIDLib.EditTypeEnum.CalculatorType;

The following VFP sample adds two new columns to the control:

with thisform.Grid1
	.Columns.Add("Column 1")
	With .Columns.Add("Column 2")
		with .Editor
			.EditType = 21 && CalculatorType
		endwith
	EndWith
endwith