locked
dropdown box RRS feed

  • Question

  • I use a dropdown box in my custom made ribbon.

    if I select and click, I get the name of the selected item in the box, which is normal.

    I have another control on the ribbon with which I can scroll thru the list of the dd box. How can I get the corresponding name in the dd box using VBA ??

    Can I also change the width and or color of the dd box??

    Tuesday, December 13, 2011 9:51 AM

Answers

  • Hi,

    let's take an example of a dropdown:

    <dropDown id="ReportName" imageMso="ViewsReportView" label="Report name" screentip="Select Sales Report" onAction="MyActionForDropdown" sizeString="WWWWWWWWWWWW" getSelectedItemIndex="GetItemIndex">
        <item id="Category" label="Sales by Category"/>
        <item id="Country" label="Sales by Country" />
        <item id="Customer" label="Sales by Customer"/>
        <item id="Employee" label="Sales by Employee"/>
        <item id="Product" label="Sales by Product"/>
      </dropDown>
    
    
    

    1. Getting the value. The easiest way I know is to have a temporary variable (TempVars collection member). You can assign a value you need within an onAction callback. Like this one:

    Public Sub MyActionForDropdown(ctrl As IRibbonControl, selectedId$, selectedIndex%)     
        TempVars("RepName").Value = selectedId  
    End Sub 
    
    

    Now you can use this value of the RepName temporary variable further in your code.

    2. You can change the width with the sizeString attribute (see an example above).

    3. I'm not sure you can. I think that the color is defined by the whole Office color schema.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    • Marked as answer by Bruce Song Monday, December 26, 2011 4:18 AM
    Tuesday, December 13, 2011 11:10 AM
  • Andrey,

    thanks for yr help

    I have solved the problem as follows:

    'Callback for ReportName getSelectedItemIndex

    Sub getItemIndex(control As IRibbonControl, ByRef returnedVal)

    returnedVal = tstindex

    End Sub

    tstindex is a temp variable. Different numbers , followed by

    RibbonUI.InvalidateControl ("ReportName")

    will change the value in the dropdown box.

    By clicking on the combobox the variable tstindex is declared to the index with the following callback

    'Callback for ReportName onAction

    Sub onAction(control as IRibbonControl, id as String, index as Integer)

    tstindex = index

    end sub

    Thanks/best regards Jantje

    • Marked as answer by Bruce Song Monday, December 26, 2011 4:18 AM
    Wednesday, December 14, 2011 6:44 PM

All replies

  • Hi,

    let's take an example of a dropdown:

    <dropDown id="ReportName" imageMso="ViewsReportView" label="Report name" screentip="Select Sales Report" onAction="MyActionForDropdown" sizeString="WWWWWWWWWWWW" getSelectedItemIndex="GetItemIndex">
        <item id="Category" label="Sales by Category"/>
        <item id="Country" label="Sales by Country" />
        <item id="Customer" label="Sales by Customer"/>
        <item id="Employee" label="Sales by Employee"/>
        <item id="Product" label="Sales by Product"/>
      </dropDown>
    
    
    

    1. Getting the value. The easiest way I know is to have a temporary variable (TempVars collection member). You can assign a value you need within an onAction callback. Like this one:

    Public Sub MyActionForDropdown(ctrl As IRibbonControl, selectedId$, selectedIndex%)     
        TempVars("RepName").Value = selectedId  
    End Sub 
    
    

    Now you can use this value of the RepName temporary variable further in your code.

    2. You can change the width with the sizeString attribute (see an example above).

    3. I'm not sure you can. I think that the color is defined by the whole Office color schema.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    • Marked as answer by Bruce Song Monday, December 26, 2011 4:18 AM
    Tuesday, December 13, 2011 11:10 AM
  • Andrey

    Thanks, this is just what I needed!

    Maybe you know too: In Microsoft Visual Basic there was a tool like a dd box (List box) and also a Combo box  with the possibility to scroll by two small arrows(up and down) on the side of the box. I have not foud this in VBA. Is there something like that in VBA which can be used in the Ribbon? I am using now a self made tool which is more complicated.

    Jantje

    Tuesday, December 13, 2011 5:12 PM
  • Jantje,

    AFAIK, no. At least I didn't see such a control. 

    BTW, here is a good article about Ribbon UI and VBA http://msdn.microsoft.com/en-us/library/dd548010(v=office.12).aspx you may find it interesting.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Tuesday, December 13, 2011 5:52 PM
  • Andrey

    sorry but I was too happy with your answer.Your answer gives the ID after I have clicked on the dd box.

    What I need is to get the right ID in the box from an outside control.

     For example:

    From another tool I have selected Employee. What I would like to see now is this name being an item in the list selected in the dd box. So get the dd box set at this item in the list.

    In simple terms: Set ddbox="Employee". This involves probably some more VBA.

    Hope you can answer this question as well. Otherwise maybe somebody else.

    Thanks

    Jantje 

     

    Tuesday, December 13, 2011 6:07 PM
  • Andrey

    thanks for reply. I know this site. I use also the book RibbonX - Customizing the Office 2007 Ribbon from Robert Martin, Ken Puls, Teresa Hennig which I can recommend.

    Jantje 

    Tuesday, December 13, 2011 6:13 PM
  • Jantje,

    understood. So you want to choose an employee name somewhere, for example, in a form and this name shold be chosen in the ribbon dd as well, right?

    I think getSelectedItemID callback will meet your needs. It depends on how you define your dd xml. If each dd item has id = Employee name, you can use this callback. If you have some employee code (id) which is numeric and it somehow correlates with the number of item, you can use getSelectedItemIndex.

     


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru
    English blog enblog.biztoolbox.ru
    Wednesday, December 14, 2011 6:45 AM
  • Andrey,

    thanks for yr help

    I have solved the problem as follows:

    'Callback for ReportName getSelectedItemIndex

    Sub getItemIndex(control As IRibbonControl, ByRef returnedVal)

    returnedVal = tstindex

    End Sub

    tstindex is a temp variable. Different numbers , followed by

    RibbonUI.InvalidateControl ("ReportName")

    will change the value in the dropdown box.

    By clicking on the combobox the variable tstindex is declared to the index with the following callback

    'Callback for ReportName onAction

    Sub onAction(control as IRibbonControl, id as String, index as Integer)

    tstindex = index

    end sub

    Thanks/best regards Jantje

    • Marked as answer by Bruce Song Monday, December 26, 2011 4:18 AM
    Wednesday, December 14, 2011 6:44 PM