Hello Friends,
I have a combobox in which diffrerent controls name are present like panel1,button1,groupbox1 ect.
now i want to make panel1 which has a string type(Because it's a element of combobox) as a control panel1
so that i can find child controls of panel 1.
If You have a solution for tihs please send replay ASAP.
Thanks
Loading
Posted Jun 21, 2011, 9:31 AM
Here, in the ControlDetails class,I'm storing the name and control type . While fetching for the particular parent, I'm getting the control type from the Collection and called the FindControls method.
Hope this solves your problems.
private void Form8_Load(object sender, EventArgs e) controls = new List();
{
FindControls(this, comboBox2);
}
List
public void FindControls(Control control, ComboBox cmbox)
{
// ComboBox cb = (ComboBox)fillControl;
cmbox.Items.Clear();
for (int i = 0; i < control.Controls.Count; i++)
{
controls.Add(new ControlDetails() { Name = control.Controls[i].Name, Type = control.Controls[i] });
cmbox.Items.Add(control.Controls[i].Name);
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
Control cc = new Control(comboBox2.Text);
object t = controls.SingleOrDefault(x => x.Name == comboBox2.Text).Type;
FindControls((Control) t, comboBox3);
}
}
public class ControlDetails
{
public string Name { get; set; }
public System.Windows.Forms.Control Type { get; set; }
}
sachin yadavPosted Jun 22, 2011, 1:12 AM
VulpesPosted Jun 21, 2011, 9:29 AM