Combobox 功能区XML-在组合框控件中获取选定的索引或项ID

Combobox 功能区XML-在组合框控件中获取选定的索引或项ID,combobox,vsto,ms-office,ribbonx,Combobox,Vsto,Ms Office,Ribbonx,我正在处理一个组合框XML功能区控件,我疯狂地想要获得所选项目的索引 这是带有组合框的功能区XML代码: <customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon> <tabs> <tab id="SearchCustomerTab" insertAfterMso="TabAddIns" label

我正在处理一个组合框XML功能区控件,我疯狂地想要获得所选项目的索引

这是带有组合框的功能区XML代码:

<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
  <tabs>

    <tab id="SearchCustomerTab" insertAfterMso="TabAddIns" label="Cliente" visible="true">
      <group id="SearchCustomerGroup" label="Cliente" autoScale="true">
        <comboBox id="CustomerComboBox" getItemCount="GetItemCountCallback" getItemLabel="GetItemLabelCallback" getItemID="GetItemIDCallback" onChange="OnChangeCallback" />
      </group>
    </tab>
  </tabs>
 </ribbon>
</customUI>
使用getItemId回调,我设置ID中每个项的索引:

Public Function GetItemIDCallback(ByVal control As Office.IRibbonControl, index As Integer) As String
    Return index.ToString

End Function
但使用onChange回调,我可以获得项目标签,但不能获得ID或所选索引:

Public Sub OnChangeCallback(ByVal control As Office.IRibbonControl, text As String)

    Debug.WriteLine("OnChangeCallback text: " & text) 'text = item label

End Sub
是否有方法使用Ribbon comboBox控件获取所选项目的索引

提前感谢,


Simone

不幸的是,无法在功能区组合框()中获取所选内容的索引

每当选择组合框的值时,onChange回调 接收文本。但是,不可能得到 选择

我已经使用了一个字典(String,CustomClass)解决了这个问题,其中String是OnChangeCallback的文本参数:

Private customClass As CustomClass
Private customDictionary As Dictionary(Of String, CustomClass)

Public Sub Ribbon_Load(ByVal ribbonUI As Office.IRibbonUI)
    Dim customList As List(Of CustomClass)

    customList = FunctionToPopulateMyList()
    customDictionary = customList.ToDictionary(Function(p) p.MyText, Function(p) p)

End Sub

Public Function GetItemLabelCallback(ByVal control As Office.IRibbonControl, index As Integer) As String

        Return oCustomDictionary.ElementAt(index).Value.MyText
End Function

Public Function GetItemCountCallback(ByVal control As Office.IRibbonControl) As Integer

        Return oCustomDictionary.Count

End Function

Public Function GetItemIDCallback(ByVal control As Office.IRibbonControl, index As Integer) As String
    Return "Item" & index.ToString & control.Id

End Function

Public Sub OnChangeCallback(ByVal control As Office.IRibbonControl, text As String)
    If (customDictionary.ContainsKey(text)) Then
        customClass = customDictionary(text)

    End If
End Function

加载外接程序时,是否可以添加一个包含最小功能区XML和控件所需的任何代码的外接程序,以便我们不必花费时间进行测试设置?根据要求添加了更多代码
Private customClass As CustomClass
Private customDictionary As Dictionary(Of String, CustomClass)

Public Sub Ribbon_Load(ByVal ribbonUI As Office.IRibbonUI)
    Dim customList As List(Of CustomClass)

    customList = FunctionToPopulateMyList()
    customDictionary = customList.ToDictionary(Function(p) p.MyText, Function(p) p)

End Sub

Public Function GetItemLabelCallback(ByVal control As Office.IRibbonControl, index As Integer) As String

        Return oCustomDictionary.ElementAt(index).Value.MyText
End Function

Public Function GetItemCountCallback(ByVal control As Office.IRibbonControl) As Integer

        Return oCustomDictionary.Count

End Function

Public Function GetItemIDCallback(ByVal control As Office.IRibbonControl, index As Integer) As String
    Return "Item" & index.ToString & control.Id

End Function

Public Sub OnChangeCallback(ByVal control As Office.IRibbonControl, text As String)
    If (customDictionary.ContainsKey(text)) Then
        customClass = customDictionary(text)

    End If
End Function