Hello,
I am using Windows application to create controls at run time but events not firing properly.
When I click on one combo box, all combo boxes values changes immediately.
Code Snippet:
private void PopulateControlsInPanel(DataTable _dt, int iTotalCon = 0)
{
iTotalCon = 6;
counter += 1;
if (counter == 1)
{
_location_Y += iHeight + 25;
}
else
{
_location_Y += iHeight + 2;
}
// button
ComboBox _com = new ComboBox();
_com.Name = "Combox" + counter;
_com.Text = "Combox" + counter;
_com.Location = new Point(80, _location_Y);
_com.DataSource = _dt;
_com.DisplayMember = "Col_Value";
_com.ValueMember = "Col_Value";
// end drop down
// lablel
Label _lab = new Label();
_lab.Name = "Lablel" + counter;
_lab.Text = "Select From " + counter;
_lab.Location = new Point(10, _location_Y);
//
iTotHeight += _location_Y;
//
pln.Controls.Add(_com);
pln.Controls.Add(_lab);
_com.SelectedIndexChanged += new System.EventHandler(this.btn_SelectedIndexChanged);
//}
}
Please provide your suggestions.
Thanks,
Loading
VulpesPosted Jul 16, 2014, 7:40 AM
_com.DataSource = _dt;
with this :
_com.DataSource = _dt.Copy();
anjan kantPosted Jul 17, 2014, 2:04 AM
Thanks! It worked fine for me.
anjan kantPosted Jul 16, 2014, 7:08 AM
Thanks for the reply. I am using the method as follows:
for (int icount = 0; icount <= _dtCSV.Rows.Count - 1; icount++)
{
PopulateControlsInPanel(_dtCSV, _iTotCol);
}
Suggestions Most welcomed!
Thanks,
Ramesh MaruthiPosted Jul 15, 2014, 10:06 AM
Bind each combo box with separate instance of dt.
foreach (ComboBox comboBox in this.Controls.OfType