ToolStripItemClickedEventArgs Does not contain value

Private ContextMenuStrip1 As New ContextMenuStrip()

    Private Sub ContextMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.reportsContextMenuStrip = ContextMenuStrip1

        Try

           AddHandler reportsContextMenuStrip.ItemClicked, AddressOf cMenu_Click   ----------<<< Handler Created
            reportsContextMenuStrip.Items.Clear()
...
SQL Connection Area
Here it gets objDataReader.Item(
...

            If objDataReader.HasRows Then
                While objDataReader.Read()
                    With reportsContextMenuStrip
                        .Items.Add(objDataReader.Item("HoverText"))
                        .Text = objDataReader.Item("ExeFileName")
                        .Name = objDataReader.Item("ExeFileName")
                       Dim tsToolStripItem As ToolStripItem = New ToolStripMenuItem()
                        tsToolStripItem.Name = objDataReader.Item("ExeFileName")

                    End With
                End While
            End If

.. close sql connection

            reportsContextMenuStrip.Visible = False

....  catch info

    End Sub

'''''''''xxxxxxxxxxxxxxxHandler Sub is here

    Private Sub cMenu_Click(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs)

        Dim myText As String
       myText = e.ClickedItem.Text <<<<<<<<<<<<<<<<<----- Has correct value for .Text
        MessageBox.Show(e.ClickedItem.Name)  <<<<<<------------------ No Value for .Name


    End Sub

      This is WInForms

      I am trying to get a value from a tsToolStripItem that has been created dynamically.  The above code almost gets me there.  I created a handler
      then when cMenu_Click event happens I get the .Text EventArgs but not the Name e.ClickedItem.Name??
      
      Any thoughts?
Charles BaldoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
In this piece of code:
            If objDataReader.HasRows Then
                While objDataReader.Read()
                    With reportsContextMenuStrip
                        .Items.Add(objDataReader.Item("HoverText"))
                        .Text = objDataReader.Item("ExeFileName")
                        .Name = objDataReader.Item("ExeFileName")
                       Dim tsToolStripItem As ToolStripItem = New ToolStripMenuItem()
                        tsToolStripItem.Name = objDataReader.Item("ExeFileName")
                    End With
                End While
            End If

Open in new window

lines 5 and 6 set the .Text and .Name on reportsContextMenuStrip. It looks like you want to set those on the new item like this perhaps:
        If objDataReader.HasRows Then
            While objDataReader.Read()
                With reportsContextMenuStrip
                    With .Items.Add(objDataReader.Item("HoverText"))
                        '.Text = objDataReader.Item("ExeFileName")
                        .Name = objDataReader.Item("ExeFileName")
                        'Dim tsToolStripItem As ToolStripItem = New ToolStripMenuItem()
                        'tsToolStripItem.Name = objDataReader.Item("ExeFileName")
                    End With
                End With
            End While
        End If

Open in new window

I commented out all lines that seem strange to me: setting the text to the ExeFileName field when you just created a new item with HoverText and also creating another new ToolStrip item without adding it to the menu both seemed wrong but maybe I misunderstood what you're trying to do here.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Charles BaldoSoftware DeveloperAuthor Commented:
Thank You,  Will try it is still a little confusing to me. I am a converting c# programmer.  The last solution  you gave me was good as well.  Thank you again
0
Charles BaldoSoftware DeveloperAuthor Commented:
Thank You,  Will try it is still a little confusing to me. I am a converting c# programmer.  The last solution  you gave me was good as well.  Thank you again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.