0

How to set selected-item programatically for RibbonComboBox in VSTO? I use C#.

i.e.

myRibbonCB.SelectedItem = "label-name";

doesnt exist.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • 2
    Possibly duplicate? https://stackoverflow.com/questions/43575080/how-to-set-selected-item-on-custom-dropdown-ribbon-control – PetLahev Feb 17 '19 at 20:28
  • 1
    You need to define callbacks in the ribbon and implement those callbacks in your C# code. The duplicate link above shows a VBA solution, try the following for a C# VSTO example: http://blogs.infoextract.in/office-ribbon-customization-vsto-using-c/ – Olle Sjögren Feb 18 '19 at 11:31
  • @OlleSjögren You might post your comment as answer, i'll accept that. – T.Todua Feb 18 '19 at 12:27

1 Answers1

1

You need to define callbacks in the ribbon and implement those callbacks in your C# code. Try the following link for a C# VSTO example: http://blogs.infoextract.in/office-ribbon-customization-vsto-using-c/

In short:

Ribbon XML:

<toggleButton id="toggleButton1" onAction="OnActionCallback" />

C#:

public void OnActionCallback(Office.IRibbonControl control, bool isPressed)
{
    if (control.Id == "checkBox1")
    {
        MessageBox.Show("You clicked " + control.Id);
    }
    else
    {
        MessageBox.Show("You clicked a different control.");
    }
}
Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51