| Bound Mode > Unbound Columns > Creating unbound columns |
The first step in using an unbound column is creating the column itself. This may be done at design time by choosing either the Append or Insert command from the list's visual editing menu. At run time, unbound columns may be added using the Add method of the Columns collection. The column must be given a name by setting its Caption property. At design time, this is done using the Columns property page. At run time, the Caption property of the appropriate Column object is set. When these actions are performed at run time, new columns are not considered as unbound columns until the list's ReBind method is executed.
Note: If you attempt to insert an unbound column in code, you may need to use the HoldFields method to ensure that the column appears at the desired position within the list:
| Example Title |
Copy Code
|
|---|---|
Dim Col As TrueDBList70.Column
With TDBList1
Set Col = .Columns.Add(1)
Col.Visible = True
Col.Caption = "Unbound"
.HoldFields
.ReBind
End With
|
|
When the list needs to display the value of an unbound column, it fires the UnboundColumnFetch event. This event supplies the user with a bookmark and a column index as the means of identifying the list cell being requested. The third argument to the event is a Variant which by default is Null, but can be changed to any desired value, and will be used to fill the contents of the cell specified by the given bookmark and column index.
| Example Title |
Copy Code
|
|---|---|
Private Sub TDBList1_UnboundColumnFetch(Bookmark As Variant, _
ByVal Col As Integer, Value As Variant)
|
|
When Recordset data is retrieved through the data control, the data is cached by the list to allow smooth scrolling operations and rapid display. As a result, many rows must be fetched at one time so that they are readily available for display. Internally, the list uses a Recordset clone when it requests data, thus allowing data to be retrieved without changing the current row of the bound Recordset managed by the Data control. Why is this important? The reason is that UnboundColumnFetch may need to fetch data unrelated to the current row position.
For example, suppose a row is being edited and the user scrolls the list vertically or horizontally. To update the display, the list will need to fetch the new data that is scrolled into view for all rows and columns on the face of the list. However, changing the current row would cause an unwanted update to occur. For this reason, the list will not allow the current row of the list or Recordset to be changed during the UnboundColumnFetch event, even through implicit means such as the FindFirst method of the Recordset. Similarly, other Recordset operations are prohibited as well during the course of this event.
Given these restrictions, how do you obtain Recordset data in order to set the values of the unbound column? There are several ways, all of which involve the use of a Recordset clone.