Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


Can I Get Collection of controls in a form having a certain property value ?

Like :

Get all Textboxes with Text="MyText"

I know we can get this by looping through all controls in a form and check the property value by reflection. But it is too costly if a form has more controls. Is there any other ways ?
Posted

1 solution

Hi ,

Please try this code

C#
Form frm = this; // please set the form you are searching from
IEnumerable<textbox> items = frm.Controls.OfType<textbox>().Where(I => I.Text == "myText");


For search within nested childs do it recursively.


Hope this help.
 
Share this answer
 
v2
Comments
Jackson K T 30-Aug-13 2:09am    
Thank you !!! It just worked :)

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