I am trying to create dynamic checkboxes in a for loop. But I am getting error not during compiling but when I run create checkbox button and run that function. Can you please tell me what I am doing wrong?
public void CreateCheckBox (int i)
{
int y = 10;
CheckBox[] _cb = new CheckBox[i];
String chkBox = "chkBox_";
for (int n = 0; n<i; n++)
{
_cb[n].Location = new Point(10, y);
_cb[n].Name= chkBox + n.ToString();
form1.Controls.Add(_cb[n]);
y+= 15;
}
}