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

   ColumnCaption as String A string expression that defines the column's caption  
  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, adding new items fail. Use the Remove method to remove a specific column. The control fires the AddColumn event when a new column is added. The DataSource property automatically adds new columns for each field found in the recordset, and add new items for each record in the recordset. You can use Add method to add computed columns. Use the HTLMCaption property to display the column's caption using HTML tags. Use the Visible property to hide a column. Use the BeginUpdate and EndUpdate methods to prevent control from painting while adding columns and items. Use the Add or PutItems method to add new items to the control. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula.

The following VB sample adds columns from a record set:

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
With List1
    .ColumnAutoResize = False
    With .Columns
        For Each f In rs.Fields
            .Add f.Name
    End With
    .PutItems rs.getRows()
End With

The following VC sample adds a column:

#include "Columns.h"
#include "Column.h"
CColumns columns = m_list.GetColumns();
CColumn column( V_DISPATCH( &columns.Add( "Column 1" ) ) );
column.SetHeaderBold( TRUE );

The following VB.NET sample adds a column:

With AxList1.Columns
    With .Add("Column 1")
        .HeaderBold = True
    End With
End With

The Add method returns a Column object in a VARIANT value, so you can use a code like follows:

With AxList1.Columns
    Dim c As EXLISTLib.Column
    c = .Add("Column 1")
    With c
        .HeaderBold = True
    End With
End With

this way, you can have the properties of the column at design time when typing the '.' character.

The following C# sample adds a column:

EXLISTLib.Column column = axList1.Columns.Add( "Column 1" ) as EXLISTLib.Column;
column.HeaderBold = true;

The following VFP sample adds a column:

with thisform.List1.Columns.Add( "Column 1" )
	.HeaderBold = .t.

Send comments on this topic.
1999-2018 Exontrol.COM, Software. All rights reserved.