How to find the controls in child panel
-
20 Maret 2012 7:16Hi,
I want to find the controls in child panel , the child panels are generated dynamically
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
Panel pnl = new Panel();
pnl.Name = "pnl" + txtDisplay.Text.Replace(" ", "");
pnl.BackColor = System.Drawing.Color.DarkGoldenrod;
pnl.Width = 300;
pnl.Height = 40;
pnl.Location = new Point(10, 10*i);
i = i + 2;
pnl.Click += new EventHandler(Panel_Click);
pnlWinForm.Controls.Add(pnl);
//Label Control
Label lbl = new Label();
lbl.Name = "lbl" + txtDisplay.Text.Replace(" ", "");
lbl.Location = new Point(10, 10);
lbl.Text = txtDisplay.Text.Replace(" ", "");
pnl.Controls.Add(lbl);
//TextBox, Combox Controls
if(cbxTypeofData.SelectedItem == "text")
{
TextBox myText = new TextBox();
myText.Name = "txt" + txtDisplay.Text.Replace(" ", "");
myText.Location = new Point(110, 10);
pnl.Controls.Add(myText);
}
else if(cbxTypeofData.SelectedItem =="password")
{
TextBox myText = new TextBox();
myText.Name = "txt" + txtDisplay.Text.Replace(" ", "");
myText.Location = new Point(110, 10);
myText.UseSystemPasswordChar = true;
pnl.Controls.Add(myText);
}
}
catch (Exception ex)
{
}
}
protected void Panel_Click(object sender, EventArgs e)
{
Control[] c = this.panel1.Controls.Find(((System.Windows.Forms.Control)(sender)).Name, true);
}
In Panel_Click method i m retriving the child panel id for example "pnl1" , i have to find the controls for child panel "pnl1"
how can i retrieve those controls for the particular child panel
Reply me its urgent
Thanks In Advance
Semua Balasan
-
22 April 2012 16:08
Hi VaraPadma,
Check below link
http://www.codeproject.com/Questions/254863/Find-controls-in-child-Panel-which-has-parent-Pane
Regards