ComponentOne True DataControl 8.0
Accessing Field Values in Code

A Field object can be accessed by indexing the collection returned by the Fields property with either the field name or the zero-based ordinal position in the collection. As with any Visual Basic collection, if you plan to use a Field object many times, it is recommended (for better performance), that you declare a Visual Basic variable of type Field. So you can establish a permanent reference to a field in code, as in the following example:

Example Title
Copy Code
Dim F As Field

Set F = TData1("CustomerID") 'using name

Set F = TData1(0) 'using ordinal index

To get or set a field’s value in code, use the Value property of the Field object:

Example Title
Copy Code
' Retrieve the value of the CustomerID field

CustomerID = TData1.Fields("CustomerID").Value

' Set the value of the CustomerID field

TData1.Fields("CustomerID").Value = CustomerID

Since Value is the default property of the Field object, it can be omitted. In fact, since Fields is the default property of the TData control, the preceding example can be shortened to:

Example Title
Copy Code
CustomerID = TData1("CustomerID")

TData1("CustomerID") = CustomerID

 

 


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

Product Support Forum  |  Documentation Feedback