shrikant mule

shrikant mule

  • NA
  • 26
  • 9.8k

Problem in adding controls dynamically in user control

Sep 28 2013 11:30 AM
I am trying to add control dynamically in user control1 but from another user control2
from this user control2
private void btnAdd_Click(object sender, EventArgs e)
        {
            TakingOrder obj = new TakingOrder();//creating object of user control1
            CheckBox chk = new CheckBox();
            chk.Text = txtItemName.Text;

            Point pt=new Point(400,400);
            System.Drawing.Size sz = new System.Drawing.Size(400, 400);
            chk.Location = System.Drawing.Point.Add(pt, sz);
            obj.panel2.Controls.Add(chk);
            //MessageBox.Show("btn may  be added");
         }
and I am calling this userControl1 from tabpage form
I think while calling I need to create object of userControl1 that time control gets reset
this is the code
private void takingOrderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            f.splitContainer1.Panel2.Controls.Clear();//here I am getting warning collection is read only
            TakingOrder obj = new TakingOrder();
            f.splitContainer1.Panel2.Controls.Add(obj);
            f.MdiParent = this;
            f.Show();
        }


Answers (1)