ComponentOne List 8.0 for ActiveX
Adding and Removing Columns

By manipulating the Columns collection, you can add or remove columns from the list at run time. You can even perform complete list configurations in code, rather than using the visual editing features.

Here is an example of how a column can be added to the list using the Columns collection:

Example Title
Copy Code
' Create a new Column 0

Dim C As TrueDBList80.Column

Set C = TDBList1.Columns.Add(0)

 

' Initialize the new Column 0

With C

    .Visible = True        ' Make it visible

    .DataField = "LAST"    ' Set the column's database field

    .Caption = "Last Name" ' Set the column's caption

End With

 

' Make Column 0 as wide as Column 1

C.Width = TDBList1.Columns(1).Width

Several key points should be noted in this example:

You can insert a new column at any position. For example:

Example Title
Copy Code
Set C = TDBList1.Columns.Add(3)

After this statement executes, the new column will be Column 3. The previous Column 3 becomes Column 4, the previous Column 4 becomes Column 5, and so on.

After a new column is added, the Count property of the Columns collection will be automatically incremented by one. You cannot create a column with an index larger than the current value of the Count property. The Count property is read-only, so you cannot append columns by setting it to a larger value.

To delete a member of the Columns collection and remove it from the list's display, use the Remove method. This is the general technique to remove an item from a collection:

Example Title
Copy Code
TDBList1.Columns.Remove 1

Or, to remove all columns from a list:

Example Title
Copy Code
While TDBList1.Columns.Count <> 0

    TDBList1.Columns.Remove 0

Wend

At run time, a newly created column is made invisible to avoid unnecessary flicker when multiple columns are created. Therefore, you must explicitly set its Visible property to True. Also, you must set the column's DataField and Caption properties, otherwise the list will display a blank column with no heading.

Note that when you set the DataField property of a column in code, you must ReBind the list to the data source in order for the new column binding to take effect.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback