I am dynamically generating Checkboxes on button click which I am adding to a panel in TableLayoutPanel.
Panel panel1=new panel();
CheckBox box = new CheckBox();
box.Name = "cb_" + count;
box.AutoSize = true;
panel1.Controls.Add(box);
tableLayoutPanel1.Controls.Add(panel1);
count++;
I need to check if these checkboxes are checked on Save button click. But when i try to retrieve the Checkbox it returns null. (But if I add the checkbox directly to the form instead of TablelayoutPanel I am able to retrieve it.)
for (int i = 0; i >= count; i++)
{
CheckBox cb = this.Controls["cb_" + i] as CheckBox;// Returns Null
if (cb.Checked)
{
//Add code
}
}
How can I get the checbox state?
this.Controls["cb_" + i]returns null or is not of typeCheckBox.