Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6718315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:17+00:00 2026-05-26T08:57:17+00:00

I have been wondering, what would be the better way to implement Locking/Disabling a

  • 0

I have been wondering, what would be the better way to implement Locking/Disabling a bunch of Ribbon UI controls by just a click?

Currently, my approach is kinda simple and basic:

private void tbtnLock_Click(object sender, RibbonControlEventArgs e)
       {
           if (tbtnLock.Checked)
           {
               control1.Enabled = false;
               control2.Enabled = false;
               control3.Enabled = false;
               //...
               //controlN.Enabled = false;
           }
           else
           {
               control1.Enabled = true;
               control2.Enabled = true;
               control3.Enabled = true;
               //...
               //controlN.Enabled = true;
           }
       }

I think it’s okay if we only have just a few controls but once we add more and more controls onto the Ribbon bar, I don’t think it’d be a good coding practice to do things like above.

Is there any cleaner and neater approach to this? Am I able to get the collection of all the controls on the Ribbon bar? Hopefully someone can give me some pointers here? Thanks very much.

EDIT:

Revised code below:

private void tbtnLock_Click(object sender, RibbonControlEventArgs e)
        {
            toggleUILockState();
        }
private void toggleUILockState()
        {
            if (group1.Items != null)
            {
                foreach (RibbonControl c in group1.Items)
                {
                    if (c.Name != "tbtnLock")
                    {
                        c.Enabled = !tbtnLock.Checked;
                    }
                }
            }
        }

I think it looks a lot better than the previous version. Thanks everyone for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:57:17+00:00Added an answer on May 26, 2026 at 8:57 am

    Well certainly the first step to improve the code would be to remove the if statement and assigned the enabled state of the control directly with the checked state of the tbtnLock control like…

    control1.Enabled = !tbtnLock.Checked;
    control2.Enabled = !tbtnLock.Checked;
    

    that would cut your code if half straight away. You may want to assign that to a bool first incase you want to do additional processing on it later (maybe some other object helps determining lock state for example)

    bool isEnabled = !tbtnLock.Checked;
    
    control1.Enabled = isEnabled;
    control2.Enabled = isEnabled;
    

    Further than that I would need to know what “ribbon” control you are using. Do you have a link?

    But as you have hinted, I would want to look at trying to find a colleciton of controls, loop through them, check if the control is not the tbtnLock control and disable/enable as needed.

    Also, I would recommend move all this code to a function outside of the event handle, in case you need to call this method from other code. Something like…

    private void tbtnLock_Click(object sender, RibbonControlEventArgs e)
    {
       UpdateRibbonState();
    }
    
    private void UpdateRibbonState(){
       //Code goes here
    }
    

    EDIT: Making assumtion that a “group” (as described in comments) has a collection of controls…

    foreach(Control c in group.Controls)
    {
       if(c.Name != "tbtnLock")
       {
          c.Enabled = !tbtnLock.Checked;
       }
    }
    

    I am not familiar with any built-in .Net ribbon controls and as there is no link to a 3rd party set) I am making a best guess at the properties available for a “group”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been wondering what is the best way to tackle this situation. Is
I was wondering what would be the best way to implement a morse code
I have been wondering how to put all the stored procedures on a SQL
I have been wondering what the best practices or ramifications are in setting up
I have been wondering about temp tables in sp's and how all that can
I have been wondering about the reload() function in python, which seems like it
After much googling I have been wondering what the benefits/differences are between mysql and
Something I have been wondering about properties for a while. When you are using
Lately i have been wondering if there is a performance difference between repeating the
There is a question I have been wondering about for ages and I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.