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 indicates the column's caption.
ReturnDescription
VariantA Column object that represents the newly added column.

Use the Caption property to change the column's caption. Use the HTMLCaption property to assign a HTML caption to a column. The AddColumn event is fired when the user adds a new column to the Columns collection. Use the Remove method to remove a column. Use the Data property to assign an extra data to a column. Use the AddItem, InsertItem, PutItems, DataSource properties to add new items to the control. Use the BeginUpdate and EndUpdate methods to maintain performance while adding new columns and items. Use the ColumnAutoResize property to specify whether the visible columns fit the control's client area.

The following VB sample adds columns to your control based on a recordset:

Set rs = CreateObject("ADODB.Recordset")
rs.Open "Orders", "Provider=Microsoft.Jet.OLEDB.3.51;Data Source= D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", 3 ' Opens the table using static mode
ComboBox1.BeginUpdate
For Each f In rs.Fields
    ComboBox1.Columns.Add f.Name
Next
ComboBox1.EndUpdate

The following VB sample changes the column's caption to display built-in HTML tags:

With ComboBox1
    With .Columns
        With .Add("Column 1")
            .HTMLCaption = "Column <b>1</b>"
        End With
    End With
End With

The following C++ sample adds a column that displays built-in HTML format in its header:

CColumn column( V_DISPATCH( &m_combobox.GetColumns().Add( "Column 1" ) ) );
column.SetHTMLCaption( "Column <b>1</b>" );

The following VB.NET sample adds a column that displays built-in HTML format in its header:

With AxComboBox1.Columns
    With .Add("1")
        .HTMLCaption = "<b>Column</b> <bgcolor=FF0000> <u>1</u> </bgcolor>"
    End With
End With

The following C# sample adds a column that displays built-in HTML format in its header:

EXCOMBOBOXLib.Column column = axComboBox1.Columns.Add("1") as EXCOMBOBOXLib.Column;
column.HTMLCaption = "<b>Column</b> <bgcolor=FF0000> <u>1</u> </bgcolor>";

The following VFP sample adds a column that displays built-in HTML format in its header:

with thisform.ComboBox1.Columns
	with .Add("1")
		.HTMLCaption = "<b>Column</b> <bgcolor=FF0000> <u>1</u> </bgcolor>"
	endwith
endwith