Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ToolStripItemClickedEventArgs Does not contain value

Posted on 2014-08-01
3
Medium Priority
?
365 Views
Last Modified: 2014-08-01
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?
0
Comment
Question by:Charles Baldo
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40235368
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
 

Author Comment

by:Charles Baldo
ID: 40235391
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
 

Author Closing Comment

by:Charles Baldo
ID: 40235392
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question