locked
Add item to a listbox in a ribbon RRS feed

  • Question

  • All

    I have code below in a VSTO-project (a customized toolbar in Outlook).  CreateListbox will create a listbox in the given ribbongroup with a name, label and the first entry in the listbox.

    AddListBox is supposed to add extra items into a given listbox.  However, I do not manage to get this working as "Add" is not a member of "RibbonControl".

    Private Sub CreateListbox(ByRef grp As RibbonGroup, strName As String, strLabel As String, strFirstItem As String)
            Dim rb = Me.Factory.CreateRibbonDropDown
            rb.Name = strName
            rb.Label = strLabel
    
            Dim item As RibbonDropDownItem
            item = Me.Factory.CreateRibbonDropDownItem()
            item.Label = strFirstItem
            rb.Items.Add(item)
    
            AddHandler rb.SelectionChanged, AddressOf RbWebsite_SelectionChanged
            grp.Items.Add(rb)
        End Sub
    
       
         
    Private Sub AddListItem(ByRef grp As RibbonGroup, ByRef lst As RibbonDropDown, strItem As String, myTab As RibbonTab)
            Dim item As RibbonDropDownItem
    
            item = Me.Factory.CreateRibbonDropDownItem()
    
            For intX As Integer = 0 To myTab.Groups.Count - 1
                For intY As Integer = 0 To myTab.Groups(intX).Items.Count - 1
                    If myTab.Groups(intX).Items(intY).Name = lst.Name Then
                        myTab.Groups(intX).Items(intY).Add(item)
                        Exit Sub
                    End If
                Next
                Exit For
            Next
    
        End Sub 
    
    


    • Edited by ino_mart Monday, September 28, 2020 2:50 PM
    Monday, September 28, 2020 2:50 PM

Answers

  • Try casting the object to the type of your control, something like this:

    DirectCast(myTab.Groups(intX).Items(intY), RibbonDropDown).Items.Add(item)

    • Marked as answer by ino_mart Tuesday, September 29, 2020 6:38 AM
    Monday, September 28, 2020 4:05 PM

All replies

  • Try casting the object to the type of your control, something like this:

    DirectCast(myTab.Groups(intX).Items(intY), RibbonDropDown).Items.Add(item)

    • Marked as answer by ino_mart Tuesday, September 29, 2020 6:38 AM
    Monday, September 28, 2020 4:05 PM
  • Dear

    This indeed solved my problem

    Tuesday, September 29, 2020 6:38 AM