Click here to Skip to main content
16,005,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using a TableLayoutPanel and add difrent controls are added to it at run time i e
TableLayoutPanel1.Controls.Add(new Textbox());
now i want wich control are added, how many and how to get that controls
any one can help me plz.
Posted

The Controls property is a TableLayoutControlCollection class so you can use the methods and properties of that class to resolve the amount of controls etc. For more info see: http://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutcontrolcollection.aspx[^]

Also the TableLayout.Controls itself can be used with an indexer, like:
TableLayoutPanel1.Controls[counter]...
 
Share this answer
 
Comments
sher ali 3-Apr-11 1:31am    
thanks for solution it works fine
Wendelius 3-Apr-11 4:01am    
You're welcome.
you can use TableLayoutPanel1.Controls.Count for how many, and loop around the TableLayoutpanel1.Controls collection, and try to check the control type like below, you can use nice switch to do replace all the if statements.
C#
foreach(control ctrl in TableLayoutPanel1.Controls)
{
   if (ctrl is TextBox())
      TextBox objTxtBox = ctrl as TextBox();
if (ctrl is CheckBox())
      CheckBox objChkBox = ctrl as CheckBox();
}


[edit] Added the pre tags[/edit]
 
Share this answer
 
v2
Comments
sher ali 3-Apr-11 1:30am    
thanks a lot dear it sol my problem

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