dynamic button and events

Dec 2, 2009 at 3:36 PM


hi there, i hope you have any ideas to solve my problem with dynamic created buttons in vb2008sp1.

'sample code......

Dim RibbonButtonDyna(3) As RibbonButton
Dim z As Int32
     While z < 3
         RibbonButtonDyna(z) = New RibbonButton
         RibbonButtonDyna(z).Text = "Button No. " & z & " pressed."
         z = z + 1
     End While

 'follow code works fine with one specified button

Private Sub RibbonPanel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RibbonPanel.Click
End Sub

now, how receive the index from clicked item or text from button which is clicked ?

best regards

Dec 15, 2009 at 7:39 AM

solved by self  ;-)

Dec 20, 2009 at 10:53 AM


I have the same problem as you. How did you resolve it?

Thank you for responding.

D. Detrain

Dec 28, 2009 at 7:28 AM

Sorry im in vacation...

here is my solution:

Public Class Form1
    Dim RibbonButtonObject() As RibbonButton

    Public Sub New()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Sub CreateButtonArray()
        Dim z As Integer
        While z < 3
            ReDim RibbonButtonObject(z)
            RibbonButtonObject(z) = New RibbonButton
            RibbonButtonObject(z).Text = "Button No " & z
            RibbonButtonObject(z).Tag = z
            AddHandler RibbonButtonObject(z).Click, AddressOf RibbonButtonObject_Click
            z = z + 1
        End While
    End Sub

    Private Sub RibbonButtonObject_Click(ByVal sender As RibbonButton, ByVal e As EventArgs) Handles MyBase.Click
        MsgBox(sender.Text & "-" & sender.Tag)
    End Sub
End Class
best regards

Dec 28, 2009 at 8:58 AM

A big thank you for your reply, it is very useful.


D. Detrain

May 16, 2013 at 1:27 PM
Hi, a new version of Ribbon is released. Please visit the new site for latest fixes, releases, information and downloads.
New site: http://officeribbon.codeplex.com/