Results 1 to 5 of 5

Thread: [RESOLVED] ComboBoxitis

  1. #1

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

    Resolved [RESOLVED] ComboBoxitis

    I am still not getting it with how to get a combo box to do what I want it to do.

    I have two datatables and 3 fields.

    Table1 = lkpMBDept
    FieldA is a string field of one character (alphanumeric) = strMBDeptID
    FieldB is a string field of 125 characters for the department name = strMBDept

    Table2 = setMBItemNumber
    FieldA is a string field of one character (alphanumeric) = strMBDepartment

    Using the comboBox properties window (as seen below) I attempted a number of variations on 6 of the Databinding properties:

    For instance, here is one of my attempts, which did not work out the way I had hoped.

    DataBindings

    SelectedItem = BindingSource Table1.FieldB
    SelectedValue = BindingSource Table2.FieldA
    Tag = none
    Text = none
    DataSource = Table1BindingSource
    DisplayMember = Table1.FieldB
    Items = Collection
    Tag = Empty
    ValueMember = Table1.FieldA

    Try as I might, I cannot seem to figure out what combination of properties or even if I have used all of the appropriate properties, to achieve what I am after with the combo box.



    Name:  DataSet.jpg
Views: 352
Size:  100.8 KBName:  comboProperties.jpg
Views: 392
Size:  60.6 KB

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

    Re: ComboBoxitis

    I cannot seem to figure out what combination of properties or even if I have used all of the appropriate properties, to achieve what I am after with the combo box.
    Perhaps it would help if you actually explained what that is. We can't tell you how to achieve something if we don't know what the something is.
    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: ComboBoxitis

    That is what I attempted to do. Let me explain again. I want to use a combo box to select from a field in a table and place the data from another field in that same table into a field in another table. To be honest I really don't know how to describe it better than I did in the previous post. So let me try again.

    The combo box needs to work with 2 tables and 3 fields.

    Table1 has two fields. Table2 has one field of interest.

    I want to show in the select list field A from table 1. When the user makes a selection from that field then the value from another field is then placed in the field in Table 2. As stated before, I have made numerous efforts using the different properties of the comboBox (see above) with no success. What I am hoping for is that someone can explain to me how to appropriately use the properties to select from one fieldA in Table1 and place the value from fieldB in Table1 into FieldA in Table2. Sorry if that is a poor job explaining, but I have no idea what more you need to explain to me. I would guess that this is probably a pretty common usage for a combo box, so my guess is that it is not difficult if one has some idea of the usage of the properties for a combobox. Am I wrong?

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

    Re: ComboBoxitis

    I'm not sure whether you have re-read your first post or not but nowhere does it actually explain what's supposed to happen when the user makes a selection. Anyway, you're not wrong about it being simple.

    First of all, you need to bind Table1 to the ComboBox in order to display the list of strMBDept values and expose the strMBDeptID value that corresponds to the selection. To do that, assign the BindingSource for Table1 to the DataSource property of the ComboBox, select the strMBDept as the DisplayMember and strMBDeptID as the ValueMember. Now, when you select an item, the corresponding strMBDeptID value will be exposed via the SelectedValue property. As such, you need to bind the SelectedValue property of the ComboBox to the strMBDepartment column of the BindingSource for Table2.

    Now, the Current property of the BindingSource for Table2 is going to have to be set to choose the record that you want to choose the department for. That is usually done using a BindingNavigator or by selection in some other bound control but you can do it in code too. When you set the Current property, either directly or indirectly, the value from the appropriate column is pushed into the SelectedValue of the ComboBox and the appropriate item text displayed. When you make a selection, the corresponding value is pushed from the SelectedValue back to the record.
    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

  5. #5

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

    Re: [RESOLVED] ComboBoxitis

    I was indeed able to make that work. Actually, I am afraid that I already had it working but what was showing up in the fields was not what was being placed into the fields. I think I forgot to refresh the screen. Anyway, I am getting the data I wanted into the correct place. I thank you.

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