Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have few forms having 1 splitcontainer. And Inside the panels of split container I have dropped 2 datagridview.


In runtime I want to get the name of the datagridviews...

I have used a for loop through the controls of a form.......It is showing only the splitcontainer...

I cannot get the controls by name... In runtime only i will get the name of the Datagridviews...

I cannot get the controls by recursive, if I am going to find a control recursively I must know the name of the control... however I will come to know the name of the control after the search only...

How to do this??

How can i get the all child controls inside a parent control...

Thanks in advance...
Mydeen.
Posted

Try the following...

C#
private void FindControl(Control ctrl, string name)
    {
      if (ctrl.Name.Equals(name))
      {
        MessageBox.Show(ctrl.Name);
        return;
      }
      foreach (Control ctr in ctrl.Controls)
      {
        FindControl(ctr, name);
      }
    }


Regards,
Vineeth
 
Share this answer
 
See here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900