locked
Ribbon dropDown populated by selection in first dropDown RRS feed

  • Question

  • I have a Word Template with two dropDowns in the Ribbon.
    I need the 2nd dropdown to be populated based on the onAction value in the first dropdown.
    I can’t seem to find a way to force the getItemCount and getItemLabel macros of the 2nd dropdown to re-execute once the first dropdown has been selected.

    Any ideas would be greatly appreciated.

    Sincerely,

    Paul Goldstein


    Paul D. Goldstein Forceware Systems, Inc.

    Wednesday, December 2, 2020 4:18 AM

Answers

  • You would do that from your call backs and setting variables that the callback code checks and allowed something on the ribbon to be clicked or not. Alternatively, you can make certain controls visible or not, again, based on variables being set and checked, and of course invalidating the ribbon at the right time.

    Here is a sample of how I setup my ribbon XML

            <group id="Group4" getLabel="GetItemLabel" image="LGP_UpdateTOC">
              <button id="ClkTAG" getVisible="GetItemVisible" image="LGP_UpdateTOC" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <button id="ClkUpdateAllFields" image="LGP_UpdateAllFieldsIcon" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <button idMso="AutoCorrect" image="LGP_FlowTable" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <separator id="Separator11" getVisible="GetItemVisible" />
    

    Notice that I try not to hard code anything into the XML, other than the image I want shown. All elements rely on callbacks to determine what is displayed. Also notice the onAction element, I refer them all to the same callback routine, which I have found simpler to adjust as required at runtime.

    To disable a certain item on the ribbon in my onAction routine called "ClkItemIcon" I am checking various variables and determining what the End User can do. Here is a clip

            If addinRegisteredOk = False Then
                'if the ProductInit routine returned false at Word's startup we do not allow the use of the ribbon controls other than those below
                Select Case control.Id
                    Case Is = "About_Button"
                        Call Globals.ThisAddIn.About()
                    Case "Register_Button"
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                    Case "Purchase_Button"
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                    Case Else
                        MsgBox(My.Resources.reg_Reactivate, MsgBoxStyle.Exclamation, ThisAddIn.LGPVersion)
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                End Select
                Exit Sub
            End If
    

    The common onAction callback is using the Control.Id passed to it from the ribbon click to determine what is allowed. In this case, if the add-in is not registered, only selective controls on the ribbon will work.

    The other way you can control what the End User can do is use the GetVisible XML element, which you see on the XML I shared above. With that you have a special callback that returns True or False if the element is visible.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, December 2, 2020 5:20 PM

All replies

  • Hi Paul,

    Checkout the ribbon.invalidate command. After you have made the adjustments you want, you have to invalidate the current displayed ribbon so that it refreshes with your changes.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, December 2, 2020 2:11 PM
  • Hi Rich,

    Thanks for writing.

    I had tried that and was getting an error at execution time on the iRibbonIU variable. I did some more searching and found out that I needed to declare the onLoad macro in the RibbonX Editor in order to initialize the iRibbonIU variable. Once I did that, I was able to execute the .Invalidate command successfully.

    Stupid question. I have three controls in the Tab. Each of them is dependent on the prior control’s being set with a user’s value: 1) dropDown selects the initial value, 2) dropDown selects a value based on the first dropDown, and 3) A button which calls a Macro that needs values set by the first two dropDowns. When I do this in a UserForm (either VBA or VB.Net), I usually disable controls #2 and #3 until I have valid values in the prior controls and then enable the succeeding control. I’m trying to do this as well, but can’t find an iRibbonIU command that allows me to disable/enable a control. Is there such a command?

    Again, thanks for your help.

    Take care,
    Paul Goldstein


    Paul D. Goldstein Forceware Systems, Inc.

    Wednesday, December 2, 2020 4:37 PM
  • You would do that from your call backs and setting variables that the callback code checks and allowed something on the ribbon to be clicked or not. Alternatively, you can make certain controls visible or not, again, based on variables being set and checked, and of course invalidating the ribbon at the right time.

    Here is a sample of how I setup my ribbon XML

            <group id="Group4" getLabel="GetItemLabel" image="LGP_UpdateTOC">
              <button id="ClkTAG" getVisible="GetItemVisible" image="LGP_UpdateTOC" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <button id="ClkUpdateAllFields" image="LGP_UpdateAllFieldsIcon" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <button idMso="AutoCorrect" image="LGP_FlowTable" getLabel="GetItemLabel" onAction="ClkItemIcon" getSupertip="GetItemSuperTip" showLabel="false" />
              <separator id="Separator11" getVisible="GetItemVisible" />
    

    Notice that I try not to hard code anything into the XML, other than the image I want shown. All elements rely on callbacks to determine what is displayed. Also notice the onAction element, I refer them all to the same callback routine, which I have found simpler to adjust as required at runtime.

    To disable a certain item on the ribbon in my onAction routine called "ClkItemIcon" I am checking various variables and determining what the End User can do. Here is a clip

            If addinRegisteredOk = False Then
                'if the ProductInit routine returned false at Word's startup we do not allow the use of the ribbon controls other than those below
                Select Case control.Id
                    Case Is = "About_Button"
                        Call Globals.ThisAddIn.About()
                    Case "Register_Button"
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                    Case "Purchase_Button"
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                    Case Else
                        MsgBox(My.Resources.reg_Reactivate, MsgBoxStyle.Exclamation, ThisAddIn.LGPVersion)
                        My.Computer.Registry.SetValue(ThisAddIn.HKEY_CU_Path, "RegAct", 1)
                        LaunchLicenseWizard()
                End Select
                Exit Sub
            End If
    

    The common onAction callback is using the Control.Id passed to it from the ribbon click to determine what is allowed. In this case, if the add-in is not registered, only selective controls on the ribbon will work.

    The other way you can control what the End User can do is use the GetVisible XML element, which you see on the XML I shared above. With that you have a special callback that returns True or False if the element is visible.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, December 2, 2020 5:20 PM
  • Hi Rich,

    That did the trick. I added the getVisible references to the XRibbon declaration for the “downstream” controls and it worked perfectly.  I do most of my work in VS, so getting into VBA is about once a month…or less. I’ve done a little bit of Ribbon interaction, so I wasn’t aware of all of the options available to each control…I’m always looking at it from code side and not as much from the control definition side.

    Thanks again for your help.

    Take care,
    Paul Goldstein


    Paul D. Goldstein Forceware Systems, Inc.

    Thursday, December 3, 2020 4:05 AM