Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi...
How do I use Linq to access a nested object like TextBoxes that are in GroupBoxes?
very Thanks.....
Posted
Comments
Smithers-Jones 17-Apr-11 7:02am    
Repost! You asked the same question just two hours earlier.
Sergey Alexandrovich Kryukov 17-Apr-11 16:10pm    
I reported repost, you can, too. I did not delete the question only because some answers are provided.
--SA
Sergey Alexandrovich Kryukov 17-Apr-11 16:12pm    
I deleted his previous Question.
No reposts, please!
--SA

This is how I did :

C#
IEnumerable<control> controls = from Control control in groupBox1.Controls
                                select control;</control>


Now you can enumerate over controls like this :

C#
foreach(Control control in controls)
{
  //Do your operation here.

}
 
Share this answer
 
Comments
Albin Abel 17-Apr-11 12:09pm    
Correct Answer. My 5.
Tarun.K.S 17-Apr-11 13:38pm    
Thanks a lot Albin! :)
Prasanta_Prince 17-Apr-11 13:57pm    
Good Answer. :)
Sergey Alexandrovich Kryukov 17-Apr-11 16:10pm    
Agree, a 5.
--SA
Tarun.K.S 18-Apr-11 2:52am    
You didn't give a 5. :(
Don't repost your question, BTW Tarun showed you a way how to use linQ with IEnumerable collections. That is an acceptable answer for your question.

But would you mind providing some more details why you want linQ here. What the result in Tarun's answer can be the same groupBox1.controls. To search a control inside? groupBox1.controls.find("Button1", true/false);. But you may be having specific reasons to use LinQ here. I am just interested to know the reason. Good to know different thoughts :)
 
Share this answer
 
Comments
Tarun.K.S 17-Apr-11 13:38pm    
Yeah I'm curious too!
Sergey Alexandrovich Kryukov 17-Apr-11 16:11pm    
Me too. This is a valid response, my 5.
--SA
Albin Abel 17-Apr-11 21:45pm    
Thanks SAKryukov.

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