Collecting all ribbon Controls and their properties

May 14, 2013 at 6:35 AM
good day guys, i am developing a control based security system, and i want to have a collection of all controls in the ribbon, taking these properties:(Text, Key, and Name),
like: string tabName = tab.Name;
            string tabText = tab.Text;
            string tabKey = tab.Key
but when i was following someone said for me to pick up the name i should say (control.Text) how then will i get the Text Property and Key property.

i am also trying this but its giving me a lot of errors, can you please assist:
private void LoadControls()
    {
        foreach (RibbonTab tab in MainRibbon.Tabs) //to clear all the controls
        {
            tab.Visible = false;

            foreach (RibbonGroup grp in tab.Groups)
            {
                grp.Visible = false;
                int count = grp.Items.Count;
                for (int i = 0; i < count; i++)
                {
                    grp.Items[i].Visible = false;
                }
            }
        }

        foreach (GMSItemMenu menu in Permissions)  //changing property to visible
        {
            if (menu.IsMenuParent)    
            {
                MainRibbon.Tabs[menu.MenuName].Visible = true;
            }
            else        
            {
                foreach (RibbonTab tab in MainRibbon.Tabs)
                {
                    foreach (RibbonGroup grp in tab.Groups)
                    {
                        if (grp.Items.Contains(menu.MenuName))
                            grp.Items[menu.MenuName].Visible = true;
                    }
                }
            }

        }

        foreach (RibbonTab tab in MainRibbon.Tabs)//enabling groups with items
        {
            foreach (RibbonGroup grp in tab.Groups)
            {
                int count = grp.Items.Count;
                bool makeVisible = false;
                for (int i = 0; i < count; i++)
                {
                    makeVisible = grp.Items[i].Visible;
                    if (makeVisible)
                    {
                        grp.Visible = true;
                        break;
                    }
                }
            }
        }
    }
May 14, 2013 at 8:03 AM
I have several questions to you:
  • what is your exact problem? You mentionend several errors - compile errors?
  • I cannot see any Key property anywhere in the Ribbon
  • RibbonTab has no Groups property
  • when you access the Items by indexer, it is the index of the RibbonItem - not the name of the RibbonItem
May 14, 2013 at 9:57 AM
thanks toAtWork for responding, i am having compile errors, there is a property called AltKey, so if i try to say (string tabKey = tab.AltKey,) its saying no definition for AltKey, and on Group i have noticed that its an equivalents of Panel


to make it clearer i want to loop through all ribbon tabs, and items on WinForms Ribbon control and insert their properties(AltKey, Name , and Text ) in the database, and enable or disable them from the database, as a way of enforcing control based security to my users
May 15, 2013 at 8:01 AM
the property AltKey should not be used. I think it was planned to implement ShortCutKeys for the Ribbon as well - this is usually what the AltKey is for.
Did I understand you correctly that "someone told you to use name and key" for lookup? There is no key of a tab or panel. You can use the Tag property as you like.
I'd rather guess that person ment you should take a Dictionary with the Text of the item as key and lookup the privilege accordingly.
Dec 12, 2013 at 4:11 PM
Hello toAtWork


I'm having a similar problem.
I created a routine list of some controls within the Ribbon, this routine is to store the name of the controls dynamically, but as I use the syntax [control name]. Name returns the error "'Name' is not a member of 'System.Windows.Forms.RibbonItem'"
    Private Sub ReadRibbon()
        For IntTab As Integer = 0 To Me.rbMain.Tabs.Count - 1
            Debug.WriteLine("tab: " & rbMain.Tabs(IntTab).Text)
            For intPnl As Integer = 0 To rbMain.Tabs(IntTab).Panels.Count - 1
                Debug.WriteLine("  pnl: " & rbMain.Tabs(IntTab).Panels(intPnl).Text)
                For intItem As Integer = 0 To rbMain.Tabs(IntTab).Panels(intPnl).Items.Count - 1
                    Debug.WriteLine("    item: " & rbMain.Tabs(IntTab).Panels(intPnl).Items(intItem).Text)
                    Debug.WriteLine("    item: " & rbMain.Tabs(IntTab).Panels(intPnl).Items(intItem).Name) '<<< The Error 
                    Select Case rbMain.Tabs(IntTab).Panels(intPnl).Items(intItem).GetType.Name
                        Case "RibbonButton"
                            Dim myBt As RibbonButton = rbMain.Tabs(IntTab).Panels(intPnl).Items(intItem)
                            For intcount As Integer = 0 To myBt.DropDownItems.Count - 1
                                Debug.WriteLine("    >>" & myBt.DropDownItems(intcount).Text)
                            Next
                        Case "RibbonButtonList"
                            Dim myBt As RibbonButtonList = rbMain.Tabs(IntTab).Panels(intPnl).Items(intItem)
                            For intcount As Integer = 0 To myBt.DropDownItems.Count - 1
                                Debug.WriteLine("    >>" & myBt.DropDownItems(intcount).Text)
                            Next
                    End Select
                Next
            Next
        Next
    End Sub
Regards