Multiple dynamic combobox databinding
-
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. -
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.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
-
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
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.
-
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.Why not set a break-point at
setSource
and see if you have data or not. - Nick Parker
My Blog -
Why not set a break-point at
setSource
and see if you have data or not. - Nick Parker
My BlogOf 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.