我正在使用comboBox XML功能区控件,并且我会疯狂地获取所选项目的索引。
这是带有comboBox的Ribbon 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>
使用getItemCount和getItemLabel回调,我可以正确填写che comboBox(oTabCustomersList是自定义类的列表):
Public Function GetItemCountCallback(ByVal control As Office.IRibbonControl) As Integer
Return oTabCustomersList.Count
End Function
Public Function GetItemLabelCallback(ByVal control As Office.IRibbonControl, index As Integer) As String
Return oTabCustomersList(index).NomeCompleto
End Function
使用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
是否可以通过功能区comboBox控件获取所选项目的索引?
谢谢,
Simone
不幸的是,不能在功能区comboBox(source)中获得选择的索引
无论何时选择组合框的值,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