BindingCollection.Add Method (VB6)

Named Arguments

Yes

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

Data Type: StdDataFormat object

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


Key

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

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

Programming Tips and Gotchas

  • The data provider object is assigned to the BindingCollection by assigning an object reference to the DataSource property. Both the DataSource and DataMember 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 drop-down 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, _
               "fname"
obcAuthors.Add txtLastName, "Text", "au_lname", fmtF1, _
               "lname"

See Also

Binding Object
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.161.193