Visual Basic Reference
A collection of data members for a data source.
A data provider can have multiple sets of data that a data consumer can choose to bind to. Each set of data is called a "data member," and be either an ADO Recordset, a Class that implements the OLE Simple Provider (OSP) interface, or an OLEDB Provider created with Visual Basic. In any case, an arbitrary but unique string can be associated with the data member, and it is this identifying string that is added to the DataMembers collection using the Add method.
When configuring a data consumer to use a complex data source, you must set both the DataSource and the DataMember properties to fully qualify the data source. For example, if you configure a TextBox control to use the Data Environment as a data source, you must set its DataSource property to the Data Environment, and its DataMember property to a specific Command object. Conversely, when you create your own complex data source, the DataMembers collection allows your data source to serve multiple data sets to any data consumer.
For example, you can create a User Control configured as a data source by setting its DataSourceBehavior to vbDataSource. In the Initialize event, use the Add method to add the identifying strings of each data member to the DataMembers collection. Consequently, when the end user sets the DataSource property to your user control, and clicks DataMembers on the Properties window, those members added to the DataMembers collection will appear in the drop-down list.
Similarly, when creating a Class configured as a data source, in the Initialize event, invoke the Add method to add the identifying strings to the DataMembers collection. Then, to configure a data consumer to use the class, set its DataSource property to the class and its DataMember property to a member of the DataMembers collection.
When a data consumer's DataSource property is set to a class or User control configured as a data source, the GetDataMember event occurs. The event contains an argument, the DataMember argument, that passes the value of the DataMember property. The event also features an argument, the Data argument, that you can use to return the data to the consumer. In other words, in the GetDataMember event, query the DataMember value to determine which data member has been requested, and set the event's Data argument to the requested data source (i.e. an ADO Recordset, OLEDB provider, or class implementing the OSP interface).
A data member can also be an empty string. When programming the GetDataMember event, be sure handle this possibility by setting a default data member.