Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
功能区XML组合框控件以清除值。。。VB.NET_Xml_Vb.net_Vsto_Ribbon - Fatal编程技术网

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

功能区XML组合框控件以清除值。。。VB.NET,xml,vb.net,vsto,ribbon,Xml,Vb.net,Vsto,Ribbon,嘿,伙计们,你们能帮我弄清楚这个吗!?我仍在研究如何在功能区XML中清除combobox控件上的值的答案。到目前为止,我还没有找到合适的解决办法 我的combobox控件相互链接,combobox2取决于combobox1的选定值,因此每次Combox1的选定值更改时,我都需要清除combobox2中的数据文本。我在VSTO中实际上没有这样做,但我在VBA回调和下拉列表中也做过类似的操作。下面是我将如何做的,只有回调将是VBA而不是VB.NET(未测试!) 为组合框定义回调: 使用getItem

嘿,伙计们,你们能帮我弄清楚这个吗!?我仍在研究如何在功能区XML中清除combobox控件上的值的答案。到目前为止,我还没有找到合适的解决办法


我的combobox控件相互链接,combobox2取决于combobox1的选定值,因此每次Combox1的选定值更改时,我都需要清除combobox2中的数据文本。

我在VSTO中实际上没有这样做,但我在VBA回调和
下拉列表中也做过类似的操作。下面是我将如何做的,只有回调将是VBA而不是VB.NET(未测试!)

为组合框定义回调:

  • 使用
    getItemCount
    getItemID
    getItemLabel
    定义组合框的内容-您必须使用某种状态才能知道如何根据第一个组合框的内容填充第二个组合框中的值

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

  • 如果您无法实现这一点,我建议使用下拉控件,它有更多的回调可用且更好的控件(回调为选择定义了一个索引,而不是组合框
    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)
    

    我现在知道了,这和下拉控制差不多

    我在combobox1上使用了Onchange属性,然后使用invalidateControl触发Combox2,然后在Combox2上使用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
    
    关于XML

    组合框1

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

    <comboBox id="cb2" label="combo2" getItemCount="getCount" getItemLabel="getItem" getText="setText_cb2"  onChange="onChange_cb2"/>
    
    
    
    很高兴听到!如果我的答案对你有帮助,你可以点击答案旁边的复选标记来结束问题。你会相信这些回拨签名很难找到吗!感谢您在.Net中包含它们!