Adding checkbox dynamically
Posted
by shiv09
on Stack Overflow
See other posts from Stack Overflow
or by shiv09
Published on 2010-04-14T07:59:07Z
Indexed on
2010/04/14
8:03 UTC
Read the original article
Hit count: 287
c#
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...
© Stack Overflow or respective owner