Ribbon Fun

Knowledge based on Nugent Package: System.Windows.Forms.Ribbon35 (3.5.8)

You create Ribbon Tabs. On the Tabs, you create Panels

In the Items property, you can customize what is in each panel (like buttons, dropdowns, checkbox, etc)

** Just by double clicking in Designer, it does *not* bring you to events. You need to go into the Code editor and drop down each of the Ribbon types you want and select an event

Make a particular Tab the Active Tab

Ribbon1.ActiveTab = RibbonTab5

Handling a RibbonTab change

All of the RibbonTabs seem to fire if you don't handle it

    Private Sub RibbonTab2_ActiveChanged(sender As Object, e As EventArgs) Handles RibbonTab2.ActiveChanged

        Dim oRib As RibbonTab = CType(sender, RibbonTab)

        If oRib.Active Then

            TabControl1.Visible = True

            TabControl1.SelectedIndex = 0



        End If

    End Sub

Adding an entry to a Ribbon Drop down on the fly

The dropdown items are RibbonLabels (items). Does not work the same like a ComboBox. You have to see if it already exists. If it does not, you create a label and then add it--requery to proceed.

        Dim oRibbonLabel As New RibbonLabel()

        oRibbonLabel = cmbBank1.DropDownItems.Find(Function(Vl As RibbonLabel) Vl.Text = cmbBank1.TextBoxText)

        If oRibbonLabel Is Nothing Then

            oRibbonLabel = New RibbonLabel

            oRibbonLabel.Text = cmbBank1.TextBoxText


        End If

        oRibbonLabel = cmbBank1.DropDownItems.Find(Function(Vl As RibbonLabel) Vl.Text = cmbBank1.TextBoxText)


            cmbBank1.SelectedItem = oRibbonLabel

        Catch ex As Exception

            MsgBox("Cannot Add this account :(")

        End Try

Using the Ribbon Drop down text


Populating a Ribbon Drop down

        While sqlReader.Read()
            Dim oRibbonLabel As New RibbonLabel()
            Dim sLine as string = ""
            sLine = sqlReader("iBank").ToString
            oRibbonLabel.Text = sLine
           If Len(sLine) > 0 And Not cmbBox.DropDownItems.Contains(oRibbonItem) Then
           end if  
        End While


Dynamic Ribbon Tab - Form Closing

    Public oLst As New List(Of RibbonTab)
    Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        For Each oRib As RibbonTab In oLst
            RemoveHandler oRib.ActiveChanged, AddressOf RibbonPanel1_Click
            For Each oPanel As RibbonPanel In oRib.Panels
                For Each oBut As RibbonButton In oPanel.Items
                    If TypeOf oBut Is RibbonButton Then
                        RemoveHandler oBut.Click, AddressOf Ribbonbutton_click
                    End If

    End Sub

Copy tab page

Private Sub CopyTabPage(ByVal Tab As Control, ByVal page As Control)
        For Each ctl As Control In Tab.Controls

            If TypeOf ctl Is TextBox Then
                Dim tbox As New TextBox
                tbox.Location = ctl.Location
                tbox.Text = ctl.Text
                tbox.Size = ctl.Size
                tbox.BackColor = ctl.BackColor
            ElseIf TypeOf ctl Is Label Then
                Dim lbl As New Label
                lbl.Location = ctl.Location
                lbl.Text = ctl.Text
            ElseIf TypeOf ctl Is GroupBox Then
                Dim grb As New GroupBox
                grb.Location = ctl.Location
                grb.Text = ctl.Text
                grb.Size = ctl.Size
                If ctl.HasChildren Then
                    CopyTabPage(ctl, grb)
                End If
            ElseIf TypeOf ctl Is DataGridView Then
                Dim dgw As New DataGridView
                dgw.Location = ctl.Location
                dgw.Text = ctl.Text

            ElseIf TypeOf ctl Is ListView Then
                Dim ctl2 As ListView = CType(ctl, ListView)
                Dim listView1 As New ListView
                listView1.Location = ctl.Location
                listView1.Text = ctl.Text
                listView1.View = View.Details
                ' Allow the user to edit item text.

                listView1.LabelEdit = True
                listView1.SmallImageList = oLstColors

                ' Allow the user to rearrange columns.

                listView1.AllowColumnReorder = True

                ' Display check boxes.

                listView1.CheckBoxes = False

                ' Select the item and subitems when selection is made.

                listView1.FullRowSelect = True

                ' Display grid lines.

                listView1.GridLines = True

                ' Sort the items in the list in ascending order.

                listView1.Sorting = SortOrder.Ascending
                listView1.Size = ctl2.Size

                For Each oColumn As ColumnHeader In ctl2.Columns
                    Dim oCol As ColumnHeader = listView1.Columns.Add(oColumn.Text)
                    oCol.Width = oColumn.Width
                listView1.Name = ctl.Name
            End If

    End Sub

Copy List View items

    Private Sub CopyListView(ByVal lv1 As ListView, ByVal lv2 As ListView)
        For Each lvi As ListViewItem In lv1.Items
            Dim newLvi As ListViewItem = lvi.Clone()
            For Each lvsi As ListViewItem.ListViewSubItem In lvi.SubItems
                newLvi.SubItems.Add(New ListViewItem.ListViewSubItem(newLvi, lvsi.Text, lvsi.ForeColor, lvsi.BackColor, lvsi.Font))
    End Sub