[ Pobierz caÅ‚ość w formacie PDF ] .Clear, and Remove collectionobject methods.For details, see the entries for each method.BindingCollection.Add Method (VB6)Named ArgumentsYesSyntaxoBindingColl.Add Object, PropertyName, DataField[, _DataFormat[, Key]]oBindingCollUse: RequiredData Type: BindingCollection objectAn object reference that returns a BindingCollection object.ObjectUse: RequiredData Type: ObjectThe data consumer object.Either a form, control, or VB data bound class.PropertyNameUse: RequiredData Type: StringThe property of the consumer object to be bound to Datafield.DataFieldUse: RequiredData Type: StringThe field of the recordset to be bound to PropertyName.DataFormatUse: Optional136 Chapter 7 The Language ReferenceVB & VBA in a Nutshell: The Language, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.BindingCollection.Add Method (VB6)Data Type: StdDataFormat objectAn object reference to a stdDataFormat object; see the Data FormatObjects entry for additional detail.KeyUse: OptionalData Type: StringA unique string value to allow direct access to the Binding object.DescriptionYou use the Add method to create the link between a field in the data providerobject and a field in the data consumer object.The Add method of the BindingCollection object is identical in concept to anyother collection s Add method.The BindingCollection object uses the Add methodto assign various properties and to create a new Binding object in the collection.Rules at a GlanceObjectmust 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 anobject reference to the DataSource property.Both the DataSource and Data-Member properties should be assigned before adding Binding objects to thecollection using the Add method." The Binding object provides simple binding, where each field of the data pro-vider is mapped to an individual property of a data consumer.Don t use theAdd method to bind complex controls or a complex bound data consumerclass.(In complex binding, the data consumer is bound to a complete row ofa recordset.)" Many VB programmers now select property names from the IntelliSense drop-down lists or use statement completion.But these features (i.e., IntelliSenseand statement completion) don t apply to the PropertyName parameter,which is a string value.This allows greater flexibility in runtime code, but cre-ates a greater chance of typo errors creeping into your code." Although key is optional, it s recommended that you provide a meaningfulkey for your Binding object.This key allows you to directly reference theBinding object in the BindingCollection later in your application." If the purpose of the format object defined by DataFormat is incompatiblewith the control being bound, the Add method generates an error.ExampleobcAuthors.DataMember = "Authors"Set obcAuthors.DataSource = oSourceobcAuthors.Add txtFirstName, "Text", "au_fname", fmtF1, _BindingCollection.Add Method (VB6) 137VB & VBA in a Nutshell: The Language, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.The Language Reference"fname"obcAuthors.Add txtLastName, "Text", "au_lname", fmtF1, _"lname"See AlsoBinding ObjectBindingCollection.Clear Method (VB6)SyntaxoBindingColl.ClearoBindingCollUse: RequiredData Type: BindingCollection objectAn object reference that returns a BindingCollection object.DescriptionRemoves all previously added Binding objects from the BindingCollection object.Programming Tips & GotchasIt s not necessary to use the Clear method before setting the BindingCollectionobject to Nothing.If all references to Binding objects within the collection havebeen set to Nothing when the BindingCollection is set to Nothing, the object isdestroyed cleanly.BindingCollection Remove.Method (VB6)Named ArgumentsYesSyntaxoBindingColl.Remove(Binding)oBindingCollUse: RequiredData Type: BindingCollection objectAn object reference that returns a BindingCollection object.BindingUse: RequiredData Type: Binding objectA reference to a binding object in the BindingCollection.DescriptionRemoves a previously added Binding object from the BindingCollection object.138 Chapter 7 The Language ReferenceVB & VBA in a Nutshell: The Language, eMatter EditionCopyright © 2000 O Reilly & Associates, Inc.All rights reserved.Binding Object (VB6)Programming Tips & GotchasUnlike most other Remove methods attached to collections in VBA, the Binding-Collection s Remove method s parameter is a reference to the object beingremoved from the collection.ExampleIn this short snippet, we access the Item method using the key assigned to theBinding object we want to remove.The method call assigns a reference to theBinding object to be removed to our local oBind object variable, which can thenbe passed to the Remove method.We then set the Bind object variable toNothing afterwards.The For Each.Next statement proves that the object hasbeen removed.Set oBind = obcAuthors.Item("address")obcAuthors.Remove oBindSet oBind = NothingFor Each oBind In obcAuthorsDebug.Print oBind.KeyNextBinding Object (VB6)DescriptionThe binding object represents the binding of one property of one form control (oranother data consumer) to a data source.The data consumer represented by theBinding object s Object property can be a form control or the form itself, or a VBclass with its DataBindingBehavior set to either vbSimpleBound or vbComplex-Bound.The data consumer s property that is updated by the data source isrepresented by the string assigned to the PropertyName property.The data sourcecan be any valid data source, such as an ADO recordset or a VB class with itsDataSouceBehavior property set to vbDataSourceFor an overview of data binding objects, including the library reference needed toaccess the object model, see the Data Binding Objects entry.See the BindingCol-lection object for more detail about data binding and an example demonstratingthe use of the Binding object
[ Pobierz całość w formacie PDF ]
zanotowane.pldoc.pisz.plpdf.pisz.plhanula1950.keep.pl
|