Charles Baldo
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("Rep ortName"))
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.Cont extMenuStr ip' to type 'System.Windows.Forms.Tool StripMenuI tem'."}
I did try casting as ContextMenuStrip but had no info to work with.
If objDR.HasRows Then
While objDR.Read()
With reportsContextMenuStrip
.Items.Add(objDR.Item("Rep
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.Cont
I did try casting as ContextMenuStrip but had no info to work with.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
getting the idea
ASKER
Thanks I will check it out in a few hours