Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When I select one of the values in my DropDown (or ComboBox, tried both), the event gets triggered correctly, but the selected item is not shown when the DropDown is closed (the box stays empty). I thought it was a default behaviour to be filled in (like e.g. Language dropdown). I have the problem with both static and dynamically loaded controls.

<DropDown
  Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown"
  Sequence="1"
  Command="MyNS.PageComponent.Command.DoAction"
  Width="150px"
  TemplateAlias="m2">
    <Menu Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown.Menu">
       <MenuSection Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown.MenuSection">
          <Controls Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown.MenuSection.Controls">
             <Button Command="SomeCommand" Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown.Button1" LabelText="Sometext" />
             <Button Command="SomeCommand" Id="MyNS.SharePoint.Ribbon.MyGroup.Dropdown.Button2" LabelText="SomeText" />
          </Controls>
       </MenuSection>
    </Menu>
</DropDown>
share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

Unfortunately, all this has to be done manually.

First of all, you will need to provide QueryCommand attribute of DropDown element, and return the correct current value manually to the properties["Value"] variable from the handler script (properties is the second parameter passed to handleCommand function of your ribbon page component).

So you will need some global js variable for storing the current value of the dropdown.

When Button1 or Button2 is pressed, you should update the global variable with the corresponding value. Then, you will have to execute "application state changed" command, to force execution of all the query commands on the page.

"Application state changed" command can be executed with the following code:

SP.Ribbon.PageManager.get_instance().get_commandDispatcher().executeCommand(Commands.CommandIds.ApplicationStateChanged,null);

I've just tested this solution and it works.

P.S. Probably you might be interested to try my opensource project SharePoint 2010 Fluent Ribbon API, which aims to simplify dealing with ribbon and provides MUCH easier interface for this kind of tasks. It supports DropDowns starting from the 1.4 release. I have an example of using DropDown, fetching value from it, etc., in FluentRibbon.Elementary sample project (in RibbonWebPart.cs), which can be found under the [Source Code] tab on CodePlex.

share|improve this answer
    
Should have known nothing is for free in SharePoint :) I'll keep your API in mind for the next project in which I'll have to change the ribbon, thanks ! –  Bart Jan 6 '12 at 7:57
    
"..and return the correct current value manually to the properties["Value"].." can u please explain what "the correct value" means? –  user8095 Apr 28 '12 at 11:47
    
@Dmitry, I mean you should leverage QueryCommand attribute and place some javascript code there, which must assign some value to properties["Value"]. This value is supposed to be equal to caption of the last clicked item of the Dropdown, i.e. it's current selected item. –  Andrey Markeev Apr 30 '12 at 11:12
    
thank u a lot. But in QueryCommand i have no selected items(even no items in dropdown). In QueryCommand i just try to set the default value and load some data. I tried to assign different values to properties["Value"], but no luck with default value. what kind of value i should set to properties["Value"] during initialization? –  user8095 Apr 30 '12 at 14:26
add comment

You don't need to do anything manually. You probably have the wrong SelectedItemDisplayMode in your xml. Try setting it to "Menu". The default does not display the item. It will only display something if you set properties.value to something.

          <DropDown
            Id="..."
            Command="..."
            SelectedItemDisplayMode="Menu"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.