How to set default value in dropdown control for Excel custom ribbon control

前端 未结 3 951
一向
一向 2021-02-09 00:54

I have created a custom Fluent Ribbon interface for Excel 2010 which includes a dropdown. Relevant XML code (simplified):



        
3条回答
  •  名媛妹妹
    2021-02-09 01:31

    It looks like you need to use VBA in order to select a default item.

    Quoting from the documentation for the dropDown element (my emphasis):

    getSelectedItemID (getSelectedItemID callback)

    Specifies the name of a callback function to be called to determine the identifier of the item to be selected in this control. The getSelectedItemID and getSelectedItemIndex attributes are mutually exclusive. If neither attribute is specified, the control SHOULD NOT display a selected item. For example, consider the following XML fragment:

    
    

    In this example, the GetGallerySelectedItemID callback function is called when the application needs to determine the selected item in the gallery. In this example the callback function returns one of the identifiers returned by the GetItemID callback function. The possible values for this attribute are defined by the ST_Delegate simple type, as specified in section 2.3.2.

    According to my reading of the documentation, you're expected to maintain the current selected item of the filter yourself. The GetSelectedItemID handler will return the currently selected item and the OnAction handler will update it.

    In the XML:

     
        
       
    
    

    And in a code module of your workbook:

    Private mCurrentItemID As Variant
    
    Sub GetSelectedItemID(control As IRibbonControl, ByRef itemID As Variant)
        If IsEmpty(mCurrentItemID) Then
            mCurrentItemID = "Filter1"
        End If
        itemID = mCurrentItemID
    End Sub
    
    Sub OnAction(control As IRibbonControl, selectedID As String, _
                 selectedIndex As Integer)
        mCurrentItemID = selectedID
    End Sub
    

提交回复
热议问题