PRB: Resetting the DataCombo RowSource Property Resets the BoundColumn Property

ID: Q238406


The information in this article applies to:
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 6.0


SYMPTOMS

When you programmatically reset the RowSource property of a Visual Basic 6.0 DataCombo or DataList control, the BoundColumn property gets reset to be the same as the ListField property. This can result in incorrect data being inserted into the Data Source record.


CAUSE

Microsoft is currently researching this problem and will post new information here as it becomes available.


RESOLUTION

Explicitly set the DataCombo's BoundColumn property to the correct field name. Then, assign the DataCombo's Text property back to itself. That is, set the Text property equal to the Text property.


STATUS

Microsoft is currently researching this problem and will post new information here as it becomes available.


MORE INFORMATION

When you set the RowSource property of the DataCombo control, it resets the BoundColumn property to the same field name as the ListField property. You can see this in the DataCombo's Properties Window at design time. When you add a DataCombo to a form and set the RowSource, RowMember, and ListField properties, the BoundColumn property initially takes on the same field name as the ListField property. The same behavior happens at run time if you reset the RowSource property in code.

The following sample application demonstrates the problem and the workaround.

Steps to reproduce:

  1. In Microsoft Visual Basic 6.0, create a new Standard EXE project.


  2. Using the Project | Components menu, select the following controls:


    • Microsoft ADO Control 6.0 (OLEDB)


    • Microsoft DataList Controls 6.0 (OLEDB)


  3. Place the following controls onto Form1:


    • ADO Data Control
      Name: ADODC1
      CommandType: adCmdTable
      ConnectionString: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Nwind.MDB
      RecordSource: Customers


    • DataCombo
      Name: DataCombo1
      RowSource: ADODC1
      ListField: CompanyName
      BoundColumn: CustomerID (note that CompanyName is the default)


    • Command Button
      Name: Command1


    • Command Button
      Name: Command2


  4. Paste the following code into Form1's Code Window:


  5. 
    Private Sub Command1_Click()
      MsgBox "Text: " & DataCombo1.Text & ", BoundText: " & DataCombo1.BoundText
    End Sub
    
    Private Sub Command2_Click()
      With DataCombo1
        Set .RowSource = Adodc1.Recordset
    '    .BoundColumn = "CustomerID"
    '    .Text = .Text
      End With
    End Sub 
  6. Run the project. Select a CompanyName in the DataCombo.


  7. Click Command1. The CompanyName is displayed in the Text property and the 5-letter CustomerID in the BoundText property.


  8. Click Command2 to programmatically change the RowSource property. Click Command1 again. The BoundText property now displays the CompanyName instead of the CustomerID.


  9. End the project. Uncomment the two lines in Command2_Click event procedure to reset the BoundColumn and Text properties in code.


  10. Run the project. Again click Command1, then Command2, then Command1. The BoundText property now displays the CustomerID even after clicking Command2.


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Malcolm Stewart, Microsoft Corporation


Additional query words:

Keywords : kbADO kbCtrl kbDataBinding kbGrpVBDB kbGrpMDAC kbDSupport
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: September 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.