Results 1 to 5 of 5

Thread: comboboxes with same datasource

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2004
    Posts
    43

    comboboxes with same datasource

    Hi guys

    In my application I have some comboboxes (three to be exact) who all share the same datasource. The problem is the following: when the user clicks one of the comboboxes and selects an item, then in the other comboxes the same item also becomes selected. How can I avoid this?

    I wrote the following code:

    VB Code:
    1. 'creation of the dataset
    2.  
    3.  Dim SQLDossier As String
    4.  
    5.         SQLDossier = "SELECT * FROM basisgegevens"
    6.         ConnectionDossier.Open()
    7.         DADossier = New OleDbDataAdapter(SQLDossier, ConnectionDossier)
    8.         DADossier.Fill(DSDossier, "tblDossier")
    9.         ConnectionDossier.Close()
    10.  
    11. 'filling of the comboboxes
    12. CmbDossier1.DataSource = Me.DSDossier
    13.         CmbDossier1.DisplayMember = "tblDossier.DOSSNR"
    14. CmbDossier2.DataSource = Me.DSDossier
    15.         CmbDossier2.DisplayMember = "tblDossier.DOSSNR"
    16. CmbDossier3.DataSource = Me.DSDossier
    17.         CmbDossier3.DisplayMember = "tblDossier.DOSSNR"

    I already tried to clear the databindings of the combobox control but that doesn't works correct.

    How should I do this?

    Any ideas?

    thnax

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    i dont know what ur exact purpose is, but i think u better remove the datasource of last two combos and add the items to those combos from the 1st one.

    this may help u

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2004
    Posts
    43
    hi,

    i found the solution: just add a new bindinfcontext to every combobox.

    cheers

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I don't understand the two previous postings.
    Surely, what you should do is to create three different datasets and fill each of them from the same dataadapter. Using your originally posted code, that would be;

    VB Code:
    1. Dim SQLDossier As String
    2. Dim dsDossier1 as New Dataset
    3. Dim dsDossier2 as New Dataset
    4. Dim dsDossier3 as New Dataset
    5.  
    6.         SQLDossier = "SELECT * FROM basisgegevens"
    7.         ConnectionDossier.Open()
    8.         DADossier = New OleDbDataAdapter(SQLDossier, ConnectionDossier)
    9.         DADossier.Fill(DSDossier1, "tblDossier")
    10.         DADossier.Fill(DSDossier2, "tblDossier")
    11.         DADossier.Fill(DSDossier3, "tblDossier")
    12.  
    13.         ConnectionDossier.Close()
    14.  
    15. 'filling of the comboboxes
    16. CmbDossier1.DataSource = DSDossier1
    17.         CmbDossier1.DisplayMember = "tblDossier.DOSSNR"
    18. CmbDossier2.DataSource = DSDossier2
    19.         CmbDossier2.DisplayMember = "tblDossier.DOSSNR"
    20. CmbDossier3.DataSource = DSDossier3
    21.         CmbDossier3.DisplayMember = "tblDossier.DOSSNR"
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2004
    Posts
    43
    Thanx taxes,

    Yes, your solution is correct but i wanted to avoid the creation of many different datasets, because my purpose is to dynamically add controls to the form so when i can use the same dataset it's much simpler.

    Thanx for the help.

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