Binding CollectionAdd Method VB Named Arguments

Syntax oBindingColl.Add Object, PropertyName, DataField[, _ DataFormat[, Key]]

oBindingColl Use: Required

Data Type: BindingCollection object

An object reference that returns a BindingCollection object.

Object

Use: Required

Data Type: Object

The data consumer object. Either a form, control, or VB data bound class.

PropertyName Use: Required

Data Type: String

The property of the consumer object to be bound to Datafield.

DataField

Use: Required

Data Type: String

The field of the recordset to be bound to PropertyName.

DataFormat

Use: Optional

136 Chapter 7- The Language Reference

Data Type: StdDataFormat object

An object reference to a stdDataFormat object; see the Data Format Objects entry for additional detail.

Use: Optional Data Type: String

A unique string value to allow direct access to the Binding object. Description

You use the Add method to create the link between a field in the data provider object and a field in the data consumer object.

The Add method of the BindingCollection object is identical in concept to any other collection's Add method. The BindingCollection object uses the Add method to assign various properties and to create a new Binding object in the collection.

Rules at a Glance

Object must be a data consumer object. It can be any form, control, form object, or even a VB class.

Programming Tips & Gotchas

• The data provider object is assigned to the BindingCollection by assigning an object reference to the DataSource property. Both the DataSource and Data-Member properties should be assigned before adding Binding objects to the collection using the Add method.

• The Binding object provides simple binding, where each field of the data provider is mapped to an individual property of a data consumer. Don't use the Add method to bind complex controls or a complex bound data consumer class. (In complex binding, the data consumer is bound to a complete row of a recordset.)

• Many VB programmers now select property names from the IntelliSense dropdown lists or use statement completion. But these features (i.e., IntelliSense and statement completion) don't apply to the PropertyName parameter, which is a string value. This allows greater flexibility in runtime code, but creates a greater chance of typo errors creeping into your code.

• Although key is optional, it's recommended that you provide a meaningful key for your Binding object. This key allows you to directly reference the Binding object in the BindingCollection later in your application.

• If the purpose of the format object defined by DataFormat is incompatible with the control being bound, the Add method generates an error.

Example obcAuthors.DataMember = "Authors" Set obcAuthors.DataSource = oSource obcAuthors.Add txtFirstName, "Text", "au_fname", fmtF1, _

BindingCollection.AddMethod (VB6) 137

"fname"

obcAuthors.Add txtLastName, "Text", "au_lname", fmtF1, _ "lname"

See Also

Binding Object

Was this article helpful?

0 0

Post a comment