CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Location
    Växjö, Sweden
    Posts
    15

    Databinding to multiple combo-boxes.

    Hi there

    This is probably a newbie question but here it goes:

    I have through databinding and a dataset, bound data to a combobox:

    Combobox1.DataSource = Dataset1.cbdata.DefaultView
    Combobox1.ValueMember = Dataset1.cbdata.cbdataIDColumn.ToString
    Combobox1.DisplayMember = Dataset1.cbdata.cbdataColumn.ToString

    Now the thing is this I have a second combobox (Combobox2) that I have bound to the same data:

    Combobox2.DataSource = Dataset1.cbdata.DefaultView
    Combobox2.ValueMember = Dataset1.cbdata.cbdataIDColumn.ToString
    Combobox2.DisplayMember = Dataset1.cbdata.cbdataColumn.ToString

    Now in my form, at runtime when I choose something in Combobox1, Combobox2 automatically gets the same value??? It changes as if It was set to be equal to combobox1 in some way, but I have no such code at all.

    I have this problem (or feature?) when using dataview's as well.

    Any help would be appreciated greatly....

  2. #2
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    here's a suggestion, don't have a clue if it will work or not, but a suggestion just the same

    combobox1.beginupdate
    your code
    combobox1.endupdate

    combobox2.beginupdate
    your code
    combobox2.endupdate

    takes a second of your time and it may work if not, I owe you a second :-)

  3. #3
    Join Date
    May 2002
    Location
    Växjö, Sweden
    Posts
    15
    Well unfortunatelly not, but thanx for trying.

    What Im thinking is, it would probably work if I created(added) another dataadapter for the same data right??

    But is this really necessary? Cause this would make the number of the dataadapters in my project to multiply quite extensivelly...well at least a few of them =P

  4. #4
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    what happens if you use the combobox2 does combobox1 change as well ? if not then you could use the the change feature of combobox1 to set the text of combobox2 to index =1

  5. #5
    Join Date
    May 2002
    Location
    Växjö, Sweden
    Posts
    15
    Regardless of which one I change, the other one changes as well.
    Setting a value in Combo1 set the same value in Combo2 and vice versa.

    What I have figured so far is because I use databinding, binding to control to the same datatable I guess unifies them in some way :P

  6. #6
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    looks like you will be adding a "2" to your code then

  7. #7
    Join Date
    May 2002
    Location
    Växjö, Sweden
    Posts
    15
    Originally posted by Jym
    looks like you will be adding a "2" to your code then
    Indeed!

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

Featured