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

VulpesRank #55 · 29.2K reputationPosted Jul 16, 2014, 3:40 AM EDT
_com.DataSource = _dt;
with this :
_com.DataSource = _dt.Copy();
Ramesh MaruthiRank #937 · 2.2K reputationPosted Jul 15, 2014, 6:06 AM EDT
Bind each combo box with separate instance of dt.
foreach (ComboBox comboBox in this.Controls.OfType
anjan kant60 reputationPosted Jul 16, 2014, 3:08 AM EDT
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,
anjan kant60 reputationPosted Jul 16, 2014, 10:04 PM EDT
Thanks! It worked fine for me.