功能区XML组合框控件清除值... VB.NET

时间:2012-09-18 23:16:53

标签: xml vb.net vsto ribbon

嘿,伙计们,你能帮我解决这个问题!?我还在研究如何在Ribbon XML中清除组合框控件上的值。到目前为止,我没有找到合适的解决方案。

我的组合框控件相互链接,组合框2依赖于combobox1选择的值,因此我需要在每次组合框选择值更改时清除组合框2中的数据文本。

2 个答案:

答案 0 :(得分:2)

我在VSTO中实际上没有这样做过,但是我已经完成了类似于VBA回调和dropDown控件的操作。以下是我将如何做,只有回调将是VBA而不是VB.NET(未经测试!)

定义组合框的回调:

  1. 使用getItemCountgetItemIDgetItemLabel来定义组合框的内容 - 您必须使用某种状态来了解如何填充组合框中的值第二个组合基于第一个内容。

  2. 使用第一个组合上的onChange回调来触发第二个组合的失效。您使用对功能区的引用并调用Invalidate重新加载整个功能区InvalidateControl(id)以使特定控件无效(例如,第二个组合)

  3. 如果你不能让它工作,我推荐dropDown控件,它有一些可用的回调和更好的控制onAction回调定义了选择的索引,而不是像comboBox onChange)这样的字符串。

    上面提到的回调的VB.NET签名:

    Function GetItemCount(control As IRibbonControl) as Integer
    
    Function GetItemID(control As IRibbonControl, itemIndex as Integer) as String
    
    Function GetItemLabel(control As IRibbonControl, itemIndex as Integer) as String
    
    Sub OnChange(control As IRibbonControl, text As String)
    

答案 1 :(得分:0)

我现在得到它,它与下拉控制几乎相同。

我在combobox1上使用了Onchange属性,然后使用invalidateControl来触发combobox2,我在其上使用getText属性来清除值。

Public Sub onChange_cb1(ByVal control As Office.IRibbonControl, ByVal text As String)
ribbon.InvalidateControl("cb2") 'to load cb2 again in the ribbon
cb2Text = "" 'global var to set the text on cb2 as empty when cb1 has selected a new value
End Sub
Public Function setText_cb2(ByVal control As Office.IRibbonControl) As String
Return cb2Text 'return value
End Function

on XML

combobox1

<comboBox id="cb1" label="combo1" getItemCount="getCount" getItemLabel="getItem" onChange="onChange_cb1"/>

combobox2

<comboBox id="cb2" label="combo2" getItemCount="getCount" getItemLabel="getItem" getText="setText_cb2"  onChange="onChange_cb2"/>