Results 1 to 4 of 4

Thread: ComboBox Behavior

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    ComboBox Behavior

    I have a combo box on a standard windows form. The combo box is bound to a field from Access table1. The Display Member is a field from the data source table. There is another field from the data source table that is the Value Member. It was my understanding that when the form is run the combo box would display a list of values (from the Display Member field) to select from (the combo box does this). It was also my understanding that the value placed in the bound field would be the value from the Value Member field (it does not do this). It actually inputs the Display Member field value. What am I doing wrong here?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ComboBox Behavior

    At a guess, I'd say that you're using the Text property of the ComboBox, which will return the text displayed in the control, which obviously comes from the property/column specified by the DisplayMember. If you want the value from the property/column specified by the ValueMember then you have to use the SelectedValue property of the ComboBox.

    If I've guessed wrongly then you're going to have to actually show us what you're doing rather than describing what you think you're doing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: ComboBox Behavior

    Here is the data properties for the combobox:

    Name:  2015-03-22_21-54-04.jpg
Views: 195
Size:  33.4 KB

    fieldA from tableA is binding source. TableB is the Datasource, Field1 TableB is the DisplayMember, and Field2 TableB is the ValueMember

    What I was expecting was the Field2 TableB value to be placed in the fieldA tableA value.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ComboBox Behavior

    It's exactly as I said. As you can see from the (DataBindings) section of your properties window, you have bound the Text property rather than the SelectedValue property. Remove the existing binding and add a new binding on the correct property and you'll be good to go.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width