The new command bar types, part 1

I have had a few questions about how to use the new command bar types available to Add-ins. These new types include the MRU button, and two different styles of combo boxes. I will discuss the MRU button here, and I will discuss how to use combo boxes in a later post.

If you were to drop down the File menu in VS and select either the Recent Files or Recent Projects flyout, you will see a MRU button list. A MRU button list is created with one call to Commands2.AddNamedCommand2, but it will create up to 25 different commands at once. Suppose you called AddNamedCommand2 with a command name of MRUButton, and the Add-in’s name was Namespace.ClassName. We will then call IDTCommandTarget.QueryStatus with a command name of Namespace.ClassName.MRUButton for the first command in the list, but for all the others, we will pass names such as Namespace.ClassName.MRUButton_1, Namespace.ClassName.MRUButton_2, etc. If you do not have an item to display, then return vsCommandStatus.vsCommandStatusUnsupported through the status parameter of QueryStatus and you will not be queried for any of the MRU buttons that follow; meaning that if you return vsCommandStatusUnsupported for MRU button #12, you will not be asked about #13, etc. The button will also not appear in the UI, it will be hidden.

Because MRU button text will often change (such as to display a different filename), the commandText parameter of the QueryStatus method can be set to contain the text do display on the button.

The Exec method works the same way, the command names Namespace.ClassName.MRUButton, Namespace.ClassName.MRUButton_1, Namespace.ClassName.MRUButton_2, etc. are passed for each item in the MRU button list when the button is selected.

Comments (1)

  1. guloosh says:


    Did you find a result for the vsCommandControlTypeDropDownCombo type? how can I add items to this combo-box?

    If so, it will so help me…

    Please, update me


Skip to main content