none
dropdown not showing text of first item in the dropdown box RRS feed

  • Question

  • I have an addin for Outlook that adds a group to the explorer ribbon. The group contains a dropdown list. The list contains Items that when clicked add text to the body of the email or appointment. I would like to either 1) define text that displays as a watermark in the box of the dropdown, or 2) display the text of the first item in the dropdown.

    I have built a dropdown using the Designer and it displays the text of the first item, which is what I want to happen. However, when I build my dropdown dynamically it just has an empty box. Clicking the box shows the dropdown list and everything works fine. I just can't get it to display the first item in the box.

    The dropdown list is built dynamically depending on selections the user makes when installing the addin. There are 5 buttons and one dropdown. Either the five buttons are visible or the dropdown is visible. Visibility is set by using the getVisible callback.

    Here is a snippet of my dynamically built ribbon xml. I appreciate any input on this issue. Thanks

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" loadImage="loadImage" onLoad="Ribbon_OnLoad">
    <ribbon>
      <tabs>
        <tab idMso="TabMail">
          <group id="InbxEmlGrp" label="New Conferencing Email " autoScale="true">
            <button id="InbxEmlGrpBtn0Std" label="Voice Conference " tag="0" screentip="Add Voice Conference Preferences to your Email or Calendar Invitation " size="normal" onAction="RbnBtnClck" getVisible="ShowButton" image="btn0" />
            <button id="InbxEml  --------- four buttons are created before the dropdown

            <dropDown id = "InbxEmlGrpBtn3Adm" label="Add All Conferencing Preferences " getItemCount="GetItemCount"  getItemID="GetItemID" getItemLabel="GetItemLabel"   tag="3" screentip="Add all of your Conferencing Preferences to your Email or Calendar Invitation with a single click " onAction="RbnBtnAdmClck" getVisible="ShowButtonAdm" image="btn3" />
            <button id="InbxEmlGrpBtnRgstr" label="Activate" getVisible="RgstrB  -------- one last button
          </group >
        </tab>

     
    Saturday, April 21, 2012 4:18 AM

Answers

  • Ken, I was able to accomplish what I wanted with a small work around. In GetItemLabel, if the item index is 0 then return "Select a Profile". In the GetSelectedItem return 0. The click event always does an InvalidateControl(DrpDwn.Id) so the selected item index is always 0 and the text field "Hint" always says "Select a Profile".

    The only drawback is when you click the dropdown the "Select a Profile" text shows in two places, in the text field and at the top of the list. If a user clicks it in the list nothing happens, so functionally it works fine, just would look better without it in the list MHO.

    Also I had to adjust the indexes and counts to take into consideration the extra item in the list.

    Perhaps this is what you were hinting at above, or not. In either case thank you for leading me to this solution.

    John

    • Marked as answer by John Svercek Monday, June 18, 2012 12:42 AM
    Monday, June 18, 2012 12:41 AM

All replies

  • Have you tried using a callback for getSelectedItemIndex, and returning the index of the item you want selected in that callback?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "John Svercek" <=?utf-8?B?Sm9obiBTdmVyY2Vr?=> wrote in message news:7071c63e-c0ff-41f3-a864-0867818ef8e9...

    I have an addin for Outlook that adds a group to the explorer ribbon. The group contains a dropdown list. The list contains Items that when clicked add text to the body of the email or appointment. I would like to either 1) define text that displays as a watermark in the box of the dropdown, or 2) display the text of the first item in the dropdown.

    I have built a dropdown using the Designer and it displays the text of the first item, which is what I want to happen. However, when I build my dropdown dynamically it just has an empty box. Clicking the box shows the dropdown list and everything works fine. I just can't get it to display the first item in the box.

    The dropdown list is built dynamically depending on selections the user makes when installing the addin. There are 5 buttons and one dropdown. Either the five buttons are visible or the dropdown is visible. Visibility is set by using the getVisible callback.

    Here is a snippet of my dynamically built ribbon xml. I appreciate any input on this issue. Thanks

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" loadImage="loadImage" onLoad="Ribbon_OnLoad">
    <ribbon>
      <tabs>
        <tab idMso="TabMail">
          <group id="InbxEmlGrp" label="New Conferencing Email " autoScale="true">
            <button id="InbxEmlGrpBtn0Std" label="Voice Conference " tag="0" screentip="Add Voice Conference Preferences to your Email or Calendar Invitation " size="normal" onAction="RbnBtnClck" getVisible="ShowButton" image="btn0" />
            <button id="InbxEml  --------- four buttons are created before the dropdown

            <dropDown id = "InbxEmlGrpBtn3Adm" label="Add All Conferencing Preferences " getItemCount="GetItemCount"  getItemID="GetItemID" getItemLabel="GetItemLabel"   tag="3" screentip="Add all of your Conferencing Preferences to your Email or Calendar Invitation with a single click " onAction="RbnBtnAdmClck" getVisible="ShowButtonAdm" image="btn3" />
            <button id="InbxEmlGrpBtnRgstr" label="Activate" getVisible="RgstrB  -------- one last button
          </group >
        </tab>

     

    Ken Slovak MVP - Outlook
    Monday, April 23, 2012 1:31 PM
  • Ken, that works but now when I click the first item (I always return 0 to getSelectedItemIndex) the click event doesn't fire. The other items in the list work fine. Any ideas?

    Thanks

    Wednesday, April 25, 2012 3:18 AM
  • I don't understand. You don't get a click event now when the dropdown is opened and the first item is selected, or when you click in the selected text in the control?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "John Svercek" <=?utf-8?B?Sm9obiBTdmVyY2Vr?=> wrote in message news:a5c019f2-e626-41e6-abb2-337cd01a2ce6...

    Ken, that works but now when I click the first item (I always return 0 to getSelectedItemIndex) the click event doesn't fire. The other items in the list work fine. Any ideas?

    Thanks


    Ken Slovak MVP - Outlook
    Wednesday, April 25, 2012 5:47 PM
  • Ken, the dropdown control shows the text from the first item. When I click the selected text in the control the dropdown list is displayed. When I click the first item in the list nothing happens, no click event. If I click any of the other items they work fine.

    John

    Wednesday, April 25, 2012 11:56 PM
  • Do you have any code you can share that demonstrates the problem? I don't see it here in my own testing.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "John Svercek" <=?utf-8?B?Sm9obiBTdmVyY2Vr?=> wrote in message news:d9475512-df9a-47a2-b90a-dc55c4aeb6d3...

    Ken, the dropdown control shows the text from the first item. When I click the selected text in the control the dropdown list is displayed. When I click the first item in the list nothing happens, no click event. If I click any of the other items they work fine.

    John


    Ken Slovak MVP - Outlook
    Thursday, April 26, 2012 2:22 PM
  • Ken, sorry for the long delay, I had some Installer issues I had to iron out. Anyway I have put together a project that demos the issue. OutlookAddin1 creates a Test Group on an Email form (OL2010). Within the Group is a dropdown control labeled “Btn Caption 0”. The dropdown has four items labeled “ItemLabel0” thru3. ItemLabel0 is displayed in the drop down box. Click the dropdown and the four buttons are displayed. Click any button but ItemLabel0 and a message is displayed. Click ItemLabel0 and nothing happens, the click event never fires. Change the GetSelectedItem to return a different value and that button will be displayed but the click event does not fire for that button.

    How do I get the selected item to fire just like the others? Here is my code.

    Public Class ThisAddIn
        Dim m_Application As Outlook.Application
        Dim m_Ribbon As Office.IRibbonUI
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            Return New Ribbon()
        End Function
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            m_Application = Me.Application
            g_OlVrsn = CInt(Left(m_Application.Version, 2))
        End Sub
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        End Sub
    End Class
    
    
    
    Imports Microsoft.Office.Core
    Imports System.Drawing
    
    <Runtime.InteropServices.ComVisible(True)> _
    Public Class Ribbon
        Implements Office.IRibbonExtensibility
        Private m_Ribbon As Office.IRibbonUI
    
        Public Sub New()
        End Sub
    
        Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
            Return CreateUI(ribbonID)
        End Function
    
    #Region "Ribbon Callbacks"
        Public Sub Ribbon_OnLoad(ByVal ribbonUI As Office.IRibbonUI)
            Try
                m_Ribbon = ribbonUI
            Catch ex As Exception
                MsgBox("Ribbon_OnLoad failed." & ControlChars.CrLf & ex.ToString, MsgBoxStyle.Critical)
            End Try
        End Sub
    
        Public Function ShowButtonAdm(ByVal control As Office.IRibbonControl) As Boolean
            Return True
        End Function
    
        Public Sub RbnBtnAdmClck(ByVal DrpDwn As Office.IRibbonControl, ByVal ItmId As String, ByVal ItmIndx As Integer)
            Try
                Call HndlBtnClck(CInt(DrpDwn.Tag), ItmIndx)
                m_Ribbon.InvalidateControl(DrpDwn.Id)
            Catch ex As Exception
                MsgBox("Message ID 0028; Error in Drop Down Click " & ControlChars.CrLf & ex.ToString, vbCritical)
            End Try
    
        End Sub
    
        Function GetItemLabel(ByVal control As IRibbonControl, ByVal index As Integer) As String
            Return "ItemLabel" & CStr(index)
        End Function
    
        Function GetItemCount(ByVal control As IRibbonControl) As Integer
            Return 4
        End Function
    
        Function GetItemID(ByVal control As IRibbonControl, ByVal index As Integer) As String
            Return "ItemID" & CStr(index)
        End Function
    
        Public Function GetSelectedItem(ByVal control As IRibbonControl) As Integer
            Return 0
        End Function
    
        Public Function loadImage(ByVal sFilename As String) As Bitmap
            loadImage = Nothing
        End Function
    #End Region
    End Class
    
    
    
    Module Module1
        Public CBButtonArray(2, 5) As String
        Public g_OlVrsn As Integer
        Public Enum OlVrsn
            OL2003 = 10
            OL2007 = 12
            OL2010 = 14
        End Enum
    
        Friend Function CreateUI(ByVal RbnID As String) As String
            Dim GrpXML As String
            Dim BtnXML As String
            Dim j As Integer
            Dim GrpId As String = "GrpID"
            Dim GrpLbl As String = "Test Group"
            Dim AtScl As String
            Dim CstmUI As String
            Dim TabXML As String
            Dim RbnXML As String
            Dim UIXML As String = ""
    
            If RbnID = "Microsoft.Outlook.Mail.Compose" Then
                For j = 0 To CBButtonArray.GetUpperBound(1)
                    CBButtonArray(0, j) = "Btn Caption " & j
                    CBButtonArray(1, j) = "Btn ToolTip " & j
                Next
                If g_OlVrsn >= OlVrsn.OL2010 Then
                    CstmUI = "http://schemas.microsoft.com/office/2009/07/customui"
                    AtScl = " "" autoScale=""true"
                Else
                    AtScl = ""
                    CstmUI = "http://schemas.microsoft.com/office/2006/01/customui"
                End If
                BtnXML = CrtAdminBtn(0, "ThisBtnID")
                GrpXML = "<group id=""" & GrpId & """ label=""" & GrpLbl & AtScl & """>" & BtnXML & "</group >"
                TabXML = "<tab idMso=""TabNewMailMessage"">" & GrpXML & "</tab>"
                RbnXML = "<ribbon>" & _
                               "<tabs>" & _
                                   TabXML & _
                               "</tabs>" & _
                           "</ribbon>"
                UIXML = "<customUI xmlns=""" & CstmUI & """ loadImage=""loadImage"" onLoad=""Ribbon_OnLoad"">" _
                            & RbnXML & "</customUI>"
            End If
            Return UIXML
        End Function
        Friend Function CrtAdminBtn(ByVal i As Integer, ByVal BtnId As String) As String
            Dim Btns As String
            Btns = "<dropDown id = """ & BtnId & "Btn" & i & "Adm"" label=""" & CBButtonArray(0, i) _
                                & " "" getItemCount=""GetItemCount"" getSelectedItemIndex =""GetSelectedItem""  " _
                                & " getItemID=""GetItemID"" getItemLabel=""GetItemLabel"" " _
                                & "  tag=""" & i & """ screentip=""" & CBButtonArray(1, i) _
                                & " "" onAction=""RbnBtnAdmClck"" getVisible=""ShowButtonAdm"" image=""btn" & i & """ />"
            Return Btns
        End Function
    
        Sub HndlBtnClck(ByVal BtnIndx As Integer, ByVal InstncId As Integer)
            MsgBox("Button Item " & InstncId & " was Clicked")
        End Sub
    End Module
    

    Thursday, May 24, 2012 5:08 AM
  • First, of all I can verify your results with your code. But let's try an experiment.
     
    Change the declaration of CBButtonArray to this:
        Public CBButtonArray(1, 4) As String
    That way you're not creating an extra dimension as you are now. It's not vital to the experiment, it's just a tweak.
     
    Then change Ribbon::GetItemCount() as follows:

    Function GetItemCount(ByVal control As IRibbonControl) As Integer

        Return 5

    End Function

    Then change Ribbon::GetSelectedItem() as follows:

    Public Function GetSelectedItem(ByVal control As IRibbonControl) As Integer

        Return 1

    End Function

    Then do your clicking on various buttons.
     
    You should see that the selected item never fires a click event. You now can click on Item0 and you will get the click event, clicking on item1 will now not fire the event.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "John Svercek" <=?utf-8?B?Sm9obiBTdmVyY2Vr?=> wrote in message news:d744487a-6ed9-45de-b512-55532163d3e1...
    Ken, sorry for the long delay, I had some Installer issues I had to iron out. Anyway I have put together a project that demos the issue. OutlookAddin1 creates a Test Group on an Email form (OL2010). Within the Group is a dropdown control labeled “Btn Caption 0”. The dropdown has four items labeled “ItemLabel0” thru3. ItemLabel0 is displayed in the drop down box. Click the dropdown and the four buttons are displayed. Click any button but ItemLabel0 and a message is displayed. Click ItemLabel0 and nothing happens, the click event never fires. Change the GetSelectedItem to return a different value and that button will be displayed but the click event does not fire for that button.

    How do I get the selected item to fire just like the others? Here is my code.

    Public Class ThisAddIn
        Dim m_Application As Outlook.Application
        Dim m_Ribbon As Office.IRibbonUI
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            Return New Ribbon()
        End Function
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            m_Application = Me.Application
            g_OlVrsn = CInt(Left(m_Application.Version, 2))
        End Sub
    
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        End Sub
    End Class
    
    
    
    Imports Microsoft.Office.Core
    Imports System.Drawing
    
    <Runtime.InteropServices.ComVisible(True)> _
    Public Class Ribbon
        Implements Office.IRibbonExtensibility
        Private m_Ribbon As Office.IRibbonUI
    
        Public Sub New()
        End Sub
    
        Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
            Return CreateUI(ribbonID)
        End Function
    
    #Region "Ribbon Callbacks"
        Public Sub Ribbon_OnLoad(ByVal ribbonUI As Office.IRibbonUI)
            Try
                m_Ribbon = ribbonUI
            Catch ex As Exception
                MsgBox("Ribbon_OnLoad failed." & ControlChars.CrLf & ex.ToString, MsgBoxStyle.Critical)
            End Try
        End Sub
    
        Public Function ShowButtonAdm(ByVal control As Office.IRibbonControl) As Boolean
            Return True
        End Function
    
        Public Sub RbnBtnAdmClck(ByVal DrpDwn As Office.IRibbonControl, ByVal ItmId As String, ByVal ItmIndx As Integer)
            Try
                Call HndlBtnClck(CInt(DrpDwn.Tag), ItmIndx)
                m_Ribbon.InvalidateControl(DrpDwn.Id)
            Catch ex As Exception
                MsgBox("Message ID 0028; Error in Drop Down Click " & ControlChars.CrLf & ex.ToString, vbCritical)
            End Try
    
        End Sub
    
        Function GetItemLabel(ByVal control As IRibbonControl, ByVal index As Integer) As String
            Return "ItemLabel" & CStr(index)
        End Function
    
        Function GetItemCount(ByVal control As IRibbonControl) As Integer
            Return 4
        End Function
    
        Function GetItemID(ByVal control As IRibbonControl, ByVal index As Integer) As String
            Return "ItemID" & CStr(index)
        End Function
    
        Public Function GetSelectedItem(ByVal control As IRibbonControl) As Integer
            Return 0
        End Function
    
        Public Function loadImage(ByVal sFilename As String) As Bitmap
            loadImage = Nothing
        End Function
    #End Region
    End Class
    
    
    
    Module Module1
        Public CBButtonArray(2, 5) As String
        Public g_OlVrsn As Integer
        Public Enum OlVrsn
            OL2003 = 10
            OL2007 = 12
            OL2010 = 14
        End Enum
    
        Friend Function CreateUI(ByVal RbnID As String) As String
            Dim GrpXML As String
            Dim BtnXML As String
            Dim j As Integer
            Dim GrpId As String = "GrpID"
            Dim GrpLbl As String = "Test Group"
            Dim AtScl As String
            Dim CstmUI As String
            Dim TabXML As String
            Dim RbnXML As String
            Dim UIXML As String = ""
    
            If RbnID = "Microsoft.Outlook.Mail.Compose" Then
                For j = 0 To CBButtonArray.GetUpperBound(1)
                    CBButtonArray(0, j) = "Btn Caption " & j
                    CBButtonArray(1, j) = "Btn ToolTip " & j
                Next
                If g_OlVrsn >= OlVrsn.OL2010 Then
                    CstmUI = "http://schemas.microsoft.com/office/2009/07/customui"
                    AtScl = " "" autoScale=""true"
                Else
                    AtScl = ""
                    CstmUI = "http://schemas.microsoft.com/office/2006/01/customui"
                End If
                BtnXML = CrtAdminBtn(0, "ThisBtnID")
                GrpXML = "<group id=""" & GrpId & """ label=""" & GrpLbl & AtScl & """>" & BtnXML & "</group >"
                TabXML = "<tab idMso=""TabNewMailMessage"">" & GrpXML & "</tab>"
                RbnXML = "<ribbon>" & _
                               "<tabs>" & _
                                   TabXML & _
                               "</tabs>" & _
                           "</ribbon>"
                UIXML = "<customUI xmlns=""" & CstmUI & """ loadImage=""loadImage"" onLoad=""Ribbon_OnLoad"">" _
                            & RbnXML & "</customUI>"
            End If
            Return UIXML
        End Function
        Friend Function CrtAdminBtn(ByVal i As Integer, ByVal BtnId As String) As String
            Dim Btns As String
            Btns = "<dropDown id = """ & BtnId & "Btn" & i & "Adm"" label=""" & CBButtonArray(0, i) _
                                & " "" getItemCount=""GetItemCount"" getSelectedItemIndex =""GetSelectedItem""  " _
                                & " getItemID=""GetItemID"" getItemLabel=""GetItemLabel"" " _
                                & "  tag=""" & i & """ screentip=""" & CBButtonArray(1, i) _
                                & " "" onAction=""RbnBtnAdmClck"" getVisible=""ShowButtonAdm"" image=""btn" & i & """ />"
            Return Btns
        End Function
    
        Sub HndlBtnClck(ByVal BtnIndx As Integer, ByVal InstncId As Integer)
            MsgBox("Button Item " & InstncId & " was Clicked")
        End Sub
    End Module
    


    Ken Slovak MVP - Outlook
    Thursday, May 24, 2012 2:59 PM
  • Ken, I had noticed that behavior ("Change the GetSelectedItem to return a different value and that button will be displayed but the click event does not fire for that button.") The reason for the question is the end user may click any button at any time and expects a response. However, it appears the selected button (at least in a dynamically built dropdown) will never cause a click event.

    My other thought is to NOT have a selected button, then all of them work. In this case my customer would like a hint in the box, like many of the built in controls have (OL Search box says "Search Inbox"). If you know how to do that, I would appreciate input.

    Thanks for your input and validating my sanity.

    John

    Tuesday, May 29, 2012 4:19 AM
  • About all I can think of would be to change the text in the drop-down. But I really never use that control in my ribbon designs, so I haven't dealt with it or with that problem previously.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "John Svercek" <=?utf-8?B?Sm9obiBTdmVyY2Vr?=> wrote in message news:e8883466-704c-41f0-9139-ac3c4bf7fd7d...

    Ken, I had noticed that behavior ("Change the GetSelectedItem to return a different value and that button will be displayed but the click event does not fire for that button.") The reason for the question is the end user may click any button at any time and expects a response. However, it appears the selected button (at least in a dynamically built dropdown) will never cause a click event.

    My other thought is to NOT have a selected button, then all of them work. In this case my customer would like a hint in the box, like many of the built in controls have (OL Search box says "Search Inbox"). If you know how to do that, I would appreciate input.

    Thanks for your input and validating my sanity.

    John


    Ken Slovak MVP - Outlook
    Tuesday, May 29, 2012 2:07 PM
  • Ken, I was able to accomplish what I wanted with a small work around. In GetItemLabel, if the item index is 0 then return "Select a Profile". In the GetSelectedItem return 0. The click event always does an InvalidateControl(DrpDwn.Id) so the selected item index is always 0 and the text field "Hint" always says "Select a Profile".

    The only drawback is when you click the dropdown the "Select a Profile" text shows in two places, in the text field and at the top of the list. If a user clicks it in the list nothing happens, so functionally it works fine, just would look better without it in the list MHO.

    Also I had to adjust the indexes and counts to take into consideration the extra item in the list.

    Perhaps this is what you were hinting at above, or not. In either case thank you for leading me to this solution.

    John

    • Marked as answer by John Svercek Monday, June 18, 2012 12:42 AM
    Monday, June 18, 2012 12:41 AM