Visual studio .net extension toolbar combo items

635 Views Asked by At

I'm trying to fill the combo box, which is on a toolbar in the vsct file. How do I specify the items in the combo? It compiles fine, but no items show up when debugging.

<Combos>
  <Combo guid="guidIDEToolbarCmdSet" id="cmdEnv" priority="0x0100" type="DropDownCombo" defaultWidth="130" idCommandList="comboItems">
    <Parent guid="guidIDEToolbarCmdSet" id="ToolbarGroup"/>
    <CommandFlag>IconAndText</CommandFlag>
    <CommandFlag>CommandWellOnly</CommandFlag>
    <Strings>
      <ButtonText>Environment:</ButtonText>
      <CommandName>Dev</CommandName>         
      <CommandName>UserTest</CommandName>
      <CommandName>LiveTest</CommandName>
      <CommandName>LiveDebug</CommandName>        
    </Strings>
  </Combo>
</Combos>

1

There are 1 best solutions below

0
On

The items of a combo box are provided by an additional command (the one specified by the idCommandList attribute); just adding multiple CommandName elements to the combobox definition within the VSCT file won´t work.

The actual items can be filled by the list command´s execute handler, for instance:

private void InvokeGetList(object sender, EventArgs e)
{
    var eventArgs = e as OleMenuCmdEventArgs;
    if (eventArgs != null)
    {
        // Note: works only for dynamic- and dropdown- combos
        IntPtr pOutValue = eventArgs.OutValue;
        if (pOutValue != IntPtr.Zero)
        {
            string[] valueStrings = new[] { "One", "Two", "Three" };
            Marshal.GetNativeVariantForObject(valueStrings, pOutValue);
        }
    }
}