Cannot change the value of a combobox RRS feed

  • Question

  • I am using the Northwinds Dataset. On my form I have a Combobox for the EmployeeID field in the Orders table. There is an OrdersBindingSource and an EmployeesBindingSource. I also have the following code:

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            EmployeeIDComboBox.DataSource = EmployeesBindingSource
            EmployeeIDComboBox.DisplayMember = "FirstName"
            EmployeeIDComboBox.ValueMember = "EmployeeID"
            EmployeeIDComboBox.DataBindings.Add("SelectedValue", OrdersBindingSource, "EmployeeID")
        End Sub

    When the form is displayed, the combobox shows the name of the employee that corresponds to the order. When I click on the combobox, I get a drop down list of all the employees. If I select an employee, the list closes up and the employee's name is displayed. So far, so good.

    But when I try to move to a different field or even close the form, nothing happens. It's like I can't do anything because the value I selected is not valid. But, if I type in a number in the combobox, I can move to a different field, move to a different record, or close the form.

    This is not the behaviour I want. I must be doing something wrong, I just can't figure out where.

    The only thing I have discovered is that this only happens with a combobox that is created by dragging the EmployeeID field from the DataSources window onto the form. If I create the combobox from the toolbox, it works fine.

    • Edited by JamesBuss Friday, June 8, 2012 3:05 PM Added paragraph about what I have discovered
    Friday, June 8, 2012 2:40 PM

All replies

  • What is before last line doing there (DataBinding.Add())? Try to remove (or comment) it.


    Friday, June 8, 2012 4:26 PM
  • If I comment out the line

    EmployeeIDComboBox.DataBindings.Add("SelectedValue", OrdersBindingSource, "EmployeeID")

    then the combobox (created by dropping the EmployeeID field on the form from the DataSources windown) starts by showing the value of the EmployeeID field (a number). The drop down shows the name of the various employees, and if I pick a name, the name is then displayed in the field, and I still can't change fields, move to a new record, or close the form.

    With the line in there, the combobox shows the name that corresponds with the value of the EmployeeID field and the drop down fucntions as expected. It's just that I can't change fields, move to a new record, or close the form.

    Friday, June 8, 2012 8:26 PM
  • Hi JamesBuss,

    I think you are talking about the issue that the value of the combobox doesn't change when you try to change the selection.

    But I could not reproduce the issue.

    Is there further progress or information you have get?

    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 15, 2012 6:17 AM