none
Excel Ribbon: Dropdown index not updating RRS feed

  • Question

  • Shortly: What do I need in order to "refresh" the screen for selected item of dropdown in Excel?

    I have two sheets, sheet1 and sheet2. I have public variables keeping track of what is selected for each one. I have for sheet1 two options, A and B and for sheet2 two options C and D.

    Here's a scenario:

    Sheet1 displays in dropdown nothing (correct).

    I change to Sheet2.

    Dropdown displays nothing (correct).

    I change the value in dropdown to C.

    I change to Sheet1.

    The dropdown displays C (incorrect).

    I change the value in dropdown to A.

    I change to Sheet2.

    The dropdown displays C (correct).

    I change to Sheet1.

    The dropdown displays A (correct).

    The variable I return in the function dd_ItemSelectedIndex (which is obviously bound to that dropdown getSelectedItemIndex) displays everytime the correct value.

    Is there something obvious I miss? If not, I will mock up code and post it.

    Thursday, November 28, 2013 8:31 PM

Answers

  • Hello KilpAr,

    The Fluent UI is a static thing. You need to use the Invalidate or InvalidateControl methods of the IRibbonUI interface as described in the Dynamically Updating the Fluent UI section of MSDN. When you call the Invalidate or InvalidateControl(string ControlID) method, the ribbon "reloads" and you can use the getSelectedItemID og getSelectedItemIndex callbacks to choose the right value (update UI). For example, if you specified in the markup getSelectedItemIndex="GetSelectedItem", you can use the following callback to set a value:

    Sub GetSelectedItem(control As IRibbonControl, ByRef returnedVal)
        returnedVal = 0
    End Sub
    
    Also I have found a similar forum thread there.
    Saturday, November 30, 2013 7:54 PM

All replies

  • I noticed from MSDN site that there is RibbonDropDown.SelectedItem.Label but how do I use it? The callback takes in control as Office.IRibbonControl, but casting it to RibbonDropDown with

    Dim rdd as RibbonDropDown = control

    causes an error.

    Friday, November 29, 2013 8:44 AM
  • Hello KilpAr,

    The Fluent UI is a static thing. You need to use the Invalidate or InvalidateControl methods of the IRibbonUI interface as described in the Dynamically Updating the Fluent UI section of MSDN. When you call the Invalidate or InvalidateControl(string ControlID) method, the ribbon "reloads" and you can use the getSelectedItemID og getSelectedItemIndex callbacks to choose the right value (update UI). For example, if you specified in the markup getSelectedItemIndex="GetSelectedItem", you can use the following callback to set a value:

    Sub GetSelectedItem(control As IRibbonControl, ByRef returnedVal)
        returnedVal = 0
    End Sub
    
    Also I have found a similar forum thread there.
    Saturday, November 30, 2013 7:54 PM
  • I have done what is recommended here and it all seems to work fine until I have 2 multi-sheet workbooks open. If I arrange them on the screen so that I can see both workbooks and their ribbons simultaneously, when I switch sheets in one workbook, the dropdown in the other ribbon also changes to show this new value even though it is incorrect for the other workbook. This appears to be a control drawing error because when I click on the other sheet to give it focus the dropdown returns to its correct value (and the other sheet is unaffected) and it does not call any of my callback functions to achieve this. So I must have both dropdowns correctly set, it is just Excel that is drawing them wrong sometimes.
    Wednesday, October 1, 2014 11:07 AM
  • Sorry, perhaps I should have pointed out that this is an Excel 2013 problem only, in earlier versions you cannot "arrange them on the screen so that I can see both workbooks and their ribbons simultaneously". Multiple windows is new to 2013.

    Wednesday, October 1, 2014 11:14 AM