Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ComboBox

ComboBox

Scheduled Pinned Locked Moved C#
wpfwcfquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bahadir Cambel
    wrote on last edited by
    #1

    Hi , I have a dataTable and this table is binded into 10 comboBoxes , but whenever I select an item in a combobox, all the comboBoxes change their value too. I guess its because of habing same source, is there any method to force to let the user select whatever he/she wants rather than changing tableName and binding each ComboBox unique ? Thanks Bahadir Cambel

    R 1 Reply Last reply
    0
    • B Bahadir Cambel

      Hi , I have a dataTable and this table is binded into 10 comboBoxes , but whenever I select an item in a combobox, all the comboBoxes change their value too. I guess its because of habing same source, is there any method to force to let the user select whatever he/she wants rather than changing tableName and binding each ComboBox unique ? Thanks Bahadir Cambel

      R Offline
      R Offline
      Ravindra Sadaphule
      wrote on last edited by
      #2

      Thats a great question!. The dafault behaviour is windows forms creates at least one currency manager object for each data sources included in the form. The currency manager is managed through BindingContext object. This behaviour is intentionally incorporated in order to keep all the controls on the form synchronized with data source. For Instance if you have two combo boxes FirstName and LastName bound to dsCustomer, then if user changes FirstName, the lastname column also changes in order to reflect the correct customer. Windows forms moves binding context beind the scenes and programmer is relived of writing code to synchronize the controls. If you do not want this feature, then you need to make a copy of the datasource and then bind it to combo boxes as illustrated in the code below. private void Form1_Load(object sender, System.EventArgs e) { System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select top 10 * from authors", "Data Source=ITD2142s;Initial Catalog=pubs;Integrated Security=SSPI;"); ds = new System.Data.DataSet(); da.Fill(ds); comboBox1.DataSource = ds.Copy().Tables[0] ; comboBox1.DisplayMember = "au_lname"; comboBox2.DataSource = ds.Copy().Tables[0] ;; comboBox2.DisplayMember = "au_fname"; } Hope this helps ;). Cheers Ravindra Sadaphule MCSD.NET

      B 1 Reply Last reply
      0
      • R Ravindra Sadaphule

        Thats a great question!. The dafault behaviour is windows forms creates at least one currency manager object for each data sources included in the form. The currency manager is managed through BindingContext object. This behaviour is intentionally incorporated in order to keep all the controls on the form synchronized with data source. For Instance if you have two combo boxes FirstName and LastName bound to dsCustomer, then if user changes FirstName, the lastname column also changes in order to reflect the correct customer. Windows forms moves binding context beind the scenes and programmer is relived of writing code to synchronize the controls. If you do not want this feature, then you need to make a copy of the datasource and then bind it to combo boxes as illustrated in the code below. private void Form1_Load(object sender, System.EventArgs e) { System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select top 10 * from authors", "Data Source=ITD2142s;Initial Catalog=pubs;Integrated Security=SSPI;"); ds = new System.Data.DataSet(); da.Fill(ds); comboBox1.DataSource = ds.Copy().Tables[0] ; comboBox1.DisplayMember = "au_lname"; comboBox2.DataSource = ds.Copy().Tables[0] ;; comboBox2.DisplayMember = "au_fname"; } Hope this helps ;). Cheers Ravindra Sadaphule MCSD.NET

        B Offline
        B Offline
        Bahadir Cambel
        wrote on last edited by
        #3

        Thanks a lor Ravinda , I used .Clone() function but it didnt work.. Well at least I should have given one more try :D I have a one more question , Is this copied dataTable will be stored logically or physically in memory ? Thanks in advance.. Bahadir Cambel

        R 1 Reply Last reply
        0
        • B Bahadir Cambel

          Thanks a lor Ravinda , I used .Clone() function but it didnt work.. Well at least I should have given one more try :D I have a one more question , Is this copied dataTable will be stored logically or physically in memory ? Thanks in advance.. Bahadir Cambel

          R Offline
          R Offline
          Ravindra Sadaphule
          wrote on last edited by
          #4

          Clone function will only copy the structure not the data. Copy function will copy both structire as well as data. Hence Copy function is more relevant in this case. The copied data will be stored physically in memory. Ravindra Sadaphule MCSD.NET

          B 1 Reply Last reply
          0
          • R Ravindra Sadaphule

            Clone function will only copy the structure not the data. Copy function will copy both structire as well as data. Hence Copy function is more relevant in this case. The copied data will be stored physically in memory. Ravindra Sadaphule MCSD.NET

            B Offline
            B Offline
            Bahadir Cambel
            wrote on last edited by
            #5

            Thanks again for great help... Bahadir Cambel

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups