Bound Mode > Unbound Columns > Implementing multiple unbound columns |
So far, our examples have demonstrated the UnboundColumnFetch event using only a single unbound column. Suppose you want to have more than one? Since the UnboundColumnFetch is fired for each unbound column of each row, only one column value may be set at a time, and each column must be identified for the value to be properly determined. The second UnboundColumnFetch argument, Col, is used to identify the column of the list for which the value is required.
Returning to the Rectangle example, the following code also displays the perimeter of the rectangle in addition to its area:
Example Title |
Copy Code
|
---|---|
Dim ucfClone As Recordset ' Global UnboundColumnFetch clone Dim ucfLength As Field Dim ucfWidth As Field Private Sub Form_Load() Data1.Refresh Set ucfClone = Data1.Recordset.Clone() Set ucfLength = ucfClone.Fields("Length") Set ucfWidth = ucfClone.Fields("Width") End Sub Private Sub TDBList1_UnboundColumnFetch(Bookmark As Variant, _ ByVal Col As Integer, Value As Variant) ucfClone.Bookmark = Bookmark Select Case TDBList1.Columns(Col).Caption Case "Area" ' Calculate "Area" column of list Value = ucfLength * ucfWidth Case "Perimeter" ' Calculate "Perimeter" column of list Value = 2 * (ucfLength + ucfWidth) End Select End Sub |
Please note the use of the column captions to identify the actual column for which the value is to be set. The Caption property (instead of the index number) is sometimes necessary to identify the proper column. If columns are added or removed at run time, each column's index number could change, resulting in different values of Col for the Area column. Since the caption text is much less ambiguous than the column number, code is easier to read, more reliable, and self-adjusting to column layout changes.