Adding checkbox dynamically
- by shiv09
public Form1 f1 = new Form1();
int p = 150;
int q = 100;
public void add()
{
//CheckBox c = new CheckBox();
//c.Location = new Point(p, q);
//c.Text = f1.sub[0];
//this.Controls.Add(c);
CheckBox chkBox = new CheckBox();
chkBox.Location = new Point(p, q);
chkBox.Text = "Checked";
chkBox.Checked = false;
chkBox.CheckState = CheckState.Checked;
chkBox.CheckedChanged += new EventHandler(chkBox_CheckedChanged);//
this.Controls.Add(chkBox);
chkBox.Text = f1.sub[1];//The problem is here...whatever value I supply to sub[] it gives the below mentioned error
}
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Here sub[] is a list in form1 which has 5 values...