Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
325
Looping through controls
posted

I am recursively looping through controls in my user control to enable/disable controls depending on security.  I am wondering how I would be able to find any toolbars in my user control since it is not in the controls collection.

  • 44743
    Suggested Answer
    posted

    If you have a reference to the UltraToolbarsManager which defines the toolbars, you can loop through its Toolbars collection. Otherwise, while you are looping through controls, if you come to a control of type UltraToolbarsDockArea, you can access its ToolbarsManager property to get to the toolbars manager on the UserControl.

  • 17259
    Offline posted

    You can use reflection.

     

     

     

    var controls = from f in control.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance)

     

    let c = f.GetValue(control) as Control

     

    where c != null

     

    select c;

    foreach (c in controls)

    c.Enabled = false;