How to Get all RadControls from the RadForm?

3 posts, 1 answers
  1. Helder
    Helder avatar
    3 posts
    Member since:
    Jun 2010

    Posted 01 Jul 2013 Link to this post

    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. Answer
    Helder
    Helder avatar
    3 posts
    Member since:
    Jun 2010

    Posted 01 Jul 2013 Link to this post

    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
    }
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 04 Jul 2013 Link to this post

    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 >>
Back to Top