1
votes

Hey guys can you help me figure this one out!? I'm still researching for an answer on how to clear the values on a combobox control in a Ribbon XML. So far I have no luck in finding an appropriate solution.

My combobox controls are linked to each other, combobox2 depends on combobox1 selected value, so I need to clear the data text in combobox2 everytime combobox1 selected value changes.

2

2 Answers

3
votes

I haven't actually done this in VSTO, but I've done similar with VBA callbacks and the dropDown control. The following is how I would do it, only the callbacks would be to VBA instead of VB.NET (untested!)

Define callbacks for your comboboxes:

  1. Use getItemCount, getItemID and getItemLabel to define the contents of the comboboxes - you will have to use some kind of state to know how to fill the values in the second combo based on the contents from the first.

  2. Use the onChange callback on the first combo to trigger an invalidation of the second combo. You use a reference to the ribbon and call Invalidate to reload the entire ribbon och InvalidateControl(id) to invalidate a specific control (e.g. the second combo)

If you cannot get this to work I recommend the dropDown control, which has a few more callbacks available and better control (the onAction callback defines an index for the selection, instead of a string like the comboBox onChange).

The VB.NET-signatures for the callbacks mentioned above:

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)
0
votes

I got it now, its pretty much the same with dropdown control.

I used the Onchange attribute on combobox1 and then using the invalidateControl to trigger combobox2 I use the getText attribute on it to clear the values.

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"/>