Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

Need Handler for ToolStripMenuItem generated dynamic

I have a ContextMenuStrip that I am creating items for dynamically with info from SQL server

        If objDR.HasRows Then
            While objDR.Read()
                With reportsContextMenuStrip
                   .Items.Add(objDR.Item("ReportName"))
                    AddHandler .Click, AddressOf cMenu_Click

                End With
            End While
        End If
---------------------------------------
    Private Sub cMenu_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim mytext As String
        mytext = DirectCast(sender, ToolStripMenuItem).Text '  <<<<<<<<< Error Here
     
    End Sub

When I click It calls cMenu_Click       {"Unable to cast object of type 'System.Windows.Forms.ContextMenuStrip' to type 'System.Windows.Forms.ToolStripMenuItem'."}

I did try casting  as ContextMenuStrip but had no info to work with.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charles Baldo

ASKER

Robert,

Thanks I will check it out in a few hours
getting the idea