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. Multiple dynamic combobox databinding

Multiple dynamic combobox databinding

Scheduled Pinned Locked Moved C#
helpwpfwcfgraphicsdesign
5 Posts 3 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.
  • I Offline
    I Offline
    Itay Sagui
    wrote on last edited by
    #1

    I have a an application tha creates several usercontrols during runtime. The usercontrol is called "Clock", and for this matter, it contains a combobox called simply "comboBox1" clocks=new Clock[4]; for (int i=0; i<4; i++) { this.clocks[i]=new Times.Clock(); this.clocks[i].Location = new System.Drawing.Point((i%2)*width, 136+(i/2)*112); this.clocks[i].Name = "clocks"+i; this.clocks[i].Size = new System.Drawing.Size(width, 112); this.clocks[i].TabIndex = 8+i; this.clocks[i].setSource(dsCities); this.Controls.Add(clocks[i]); } the dsCities is a DataSet that has one table. now the problem is with the setSource function: public void setSource(DataSet data) { this.comboBox1.DisplayMember="City"; this.comboBox1.DataSource = data.Tables[0]; this.comboBox1.SelectedIndex=0; } The function works fine for controls that where created on design-time, but doesn't seem to perform the data-binding itself when called from a run-time control. Did anyone ever encounter this behavior? Any help would be welcome.

    S N 2 Replies Last reply
    0
    • I Itay Sagui

      I have a an application tha creates several usercontrols during runtime. The usercontrol is called "Clock", and for this matter, it contains a combobox called simply "comboBox1" clocks=new Clock[4]; for (int i=0; i<4; i++) { this.clocks[i]=new Times.Clock(); this.clocks[i].Location = new System.Drawing.Point((i%2)*width, 136+(i/2)*112); this.clocks[i].Name = "clocks"+i; this.clocks[i].Size = new System.Drawing.Size(width, 112); this.clocks[i].TabIndex = 8+i; this.clocks[i].setSource(dsCities); this.Controls.Add(clocks[i]); } the dsCities is a DataSet that has one table. now the problem is with the setSource function: public void setSource(DataSet data) { this.comboBox1.DisplayMember="City"; this.comboBox1.DataSource = data.Tables[0]; this.comboBox1.SelectedIndex=0; } The function works fine for controls that where created on design-time, but doesn't seem to perform the data-binding itself when called from a run-time control. Did anyone ever encounter this behavior? Any help would be welcome.

      S Offline
      S Offline
      Smitha Nishant
      wrote on last edited by
      #2

      At what point are you calling the DataBind method? At the Page_Load()? Smitha Every person, all the events of your life, are there because you have drawn them there. What you choose to do with them is up to you. -- Richard Bach

      I 1 Reply Last reply
      0
      • S Smitha Nishant

        At what point are you calling the DataBind method? At the Page_Load()? Smitha Every person, all the events of your life, are there because you have drawn them there. What you choose to do with them is up to you. -- Richard Bach

        I Offline
        I Offline
        Itay Sagui
        wrote on last edited by
        #3

        This is a WinForm application, not a web-based one. The data-binding is made after the call to the InitializeComponent() function, in the form's constructor.

        1 Reply Last reply
        0
        • I Itay Sagui

          I have a an application tha creates several usercontrols during runtime. The usercontrol is called "Clock", and for this matter, it contains a combobox called simply "comboBox1" clocks=new Clock[4]; for (int i=0; i<4; i++) { this.clocks[i]=new Times.Clock(); this.clocks[i].Location = new System.Drawing.Point((i%2)*width, 136+(i/2)*112); this.clocks[i].Name = "clocks"+i; this.clocks[i].Size = new System.Drawing.Size(width, 112); this.clocks[i].TabIndex = 8+i; this.clocks[i].setSource(dsCities); this.Controls.Add(clocks[i]); } the dsCities is a DataSet that has one table. now the problem is with the setSource function: public void setSource(DataSet data) { this.comboBox1.DisplayMember="City"; this.comboBox1.DataSource = data.Tables[0]; this.comboBox1.SelectedIndex=0; } The function works fine for controls that where created on design-time, but doesn't seem to perform the data-binding itself when called from a run-time control. Did anyone ever encounter this behavior? Any help would be welcome.

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          Why not set a break-point at setSource and see if you have data or not. - Nick Parker
            My Blog

          I 1 Reply Last reply
          0
          • N Nick Parker

            Why not set a break-point at setSource and see if you have data or not. - Nick Parker
              My Blog

            I Offline
            I Offline
            Itay Sagui
            wrote on last edited by
            #5

            Of course I set a breakpoint there. That's in the Debugging101 course. The problem is that when I put a breakpoint in the setSource function, all I see is that the DataMemeber is set okay, but when the DataSource is assigned, its value doesn't change, and the value of DataMember if set to "". I actually managed to solve this specific problem, by calling the setSource function only after the control was added to the form. However, I did encounter the same problem somewhere else in the application, when I tried to add more clocks.

            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