Filling RibbonComboBox Items from DataGridView headers.

Sep 21, 2013 at 5:39 PM
Using VS 2012 (visual basic), I am reading the header row of a DataGridView and if a specified header exists then a specified Item is written to ComboBox1. The code works fine with a ms ComboBox but throws an error with a RibbonComboBox. The visual basic code follows:
        Dim dropDownItemsByColumnHeader As New Dictionary(Of String, String) From {{"mL/min", "Flow"}, {"inHg", "Vacuum"}, {"Celcius", "Temperature"}, {"rhumidity", "Relative Humidity"}}

        Dim columnHeaders = Me.DataGridView1.Columns.Cast(Of DataGridViewColumn)().Select(Function(column) column.HeaderText)

        For Each columnHeader In dropDownItemsByColumnHeader.Keys

            If columnHeaders.Contains(columnHeader) Then

                Form1.ComboBox1.Items.Add(dropDownItemsByColumnHeader(columnHeader))

            End If

        Next
When I change the code to:
Form1.RibbonComboBox1.DropDownItems.Add(dropDownItemsByColumnHeader(columnHeader))
then the portion of the code "(dropDownItemsByColumnHeader(columnHeader))" throws an error stating:
Value of type 'string' cannot be converted to 'System.Windows.Form.RibbonItem'
Any assistance would be greatly appreciated.
Sep 21, 2013 at 6:33 PM
You cannot add a string to the RibbonComboBox! You need to create a RibbonItem, e.g. a RibbonLabel to add.
Pseudo code (I don't do VB):
        For Each columnHeader In dropDownItemsByColumnHeader.Keys
            If columnHeaders.Contains(columnHeader) Then
                Dim lbl as new RibbonLabel()
                lbl.Text = dropDownItemsByColumnHeader(columnHeader)
                Form1.RibbonComboBox1.DropDownItems.Add(lbl)
            End If
        Next
Sep 21, 2013 at 7:52 PM
Thank you, toAtWork, for taking the time to answer my question. Works great!