This is a migrated thread and some comments may be shown as answers.

How to Get all RadControls from the RadForm?

2 Answers 354 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Helder
Top achievements
Rank 1
Helder asked on 01 Jul 2013, 10:55 AM
I need to get all the controls from the radform to get some properties and configure it in runtime.
The components i have in the form is:
- RadTextbox
- RadMulticolumnCombobox
- RadPageView
- RadLabel
- RadGridView.

How i can get all controls and childs in the form?

2 Answers, 1 is accepted

Sort by
0
Accepted
Helder
Top achievements
Rank 1
answered on 01 Jul 2013, 04:47 PM
i got the solution:

i create this function to get all controls from a type:
public IEnumerable<Control> GetAll(Control control, Type type)
 {
            var controls = control.Controls.Cast<Control>();
 
            return controls.SelectMany(ctrl => GetAll(ctrl, type))
                                      .Concat(controls)
                                      .Where(c => c.GetType() == type);
 }

and use this to get the control and do some operations:
var q = GetAll(this, typeof(RadTextBox));
foreach (RadTextBox frtb in q)
{
   //operations with the control here
}
0
Stefan
Telerik team
answered on 04 Jul 2013, 08:12 AM
Hello Helder,

I can confirm that this is a valid approach to get the controls of a certain type on a Form. Thank you for sharing your solution with the community.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
General Discussions
Asked by
Helder
Top achievements
Rank 1
Answers by
Helder
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or