ad_handlers!!

How do u combine them!


catagoryName = node.SelectSingleNode("name")

filepath = node.SelectSingleNode("filepath")

description = node.SelectSingleNode("description")

Dim menuItem As ToolStripItem = TheHolymenu2.DropDownItems.Add(catagoryName.InnerText)

menuItem.Tag = filepath.InnerText

AddHandler menuItem.Click, AddressOf AppMenuItem_Click

menuItem.Tag = description.InnerText

AddHandler menuItem.MouseEnter, AddressOf AppMenuItem_Enter

AddHandler menuItem.MouseLeave, AddressOf AppMenuItem_Leave

Next


 


u see, when i click on the menuitem i want the ad_handler: MouseClick to occur

and when i enter, ad_handler: mouseenter should occur

but instead, it reads the description.innertext for both, i know the problem, but i cant find a way round it!

Heres the ad_handlers:

MouseClick:

Protected Sub AppMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)

Try

Dim filename As String = DirectCast(sender, ToolStripItem).Tag

Dim app As New Process()

app.StartInfo = New ProcessStartInfo(filename)

app.Start()

Catch ex As Exception

MsgBox("Filepath is Incorrect", MsgBoxStyle.Critical, "Error")

End Try

End Sub


 

MouseEnter:

Protected Sub AppMenuItem_Enter(ByVal sender As Object, ByVal e As EventArgs)

Try

Dim filename As String = DirectCast(sender, ToolStripItem).Tag

TextBox6.Text = (filename)

Catch ex As Exception

MsgBox("Description is Corrupt", MsgBoxStyle.Critical, "Error")

End Try

End Sub


 

MouseLeave:

Protected Sub AppMenuItem_Leave(ByVal sender As Object, ByVal e As EventArgs)

Try

TextBox6.Text = ""

Catch ex As Exception

End Try

End Sub


 


Any help will be GREATLY appreciated


Answer this question

ad_handlers!!

  • Sajid Ahmed

    The problem is that the ToolStripItem's Tag property isn't read until an event actually occurs. By that time, you've set it to description.InnerText; the filepath value is lost.

    I would create a class (MenuItemInfo) to contain both values:



    Protected Class menuItemInfo
       Public FilePath As String
       Public Description As String
    End
    Class

     


    Set the two values when you create the menuItem:



    Dim miInfo As New menuItemInfo
    miInfo.FilePath = filepath.InnerText
    miInfo.Description = description.InnerText
    menuItem.Tag = miInfo

     


    Finally, read the desired value in the event procedure:



    Dim menuItem As ToolStripItem = DirectCast(sender, ToolStripItem)
    Dim miInfo As menuItemInfo = DirectCast(menuItem.Tag, menuItemInfo)
    Dim filename As String = miInfo.FilePath

     


  • Steve Russell

    thx a lot!

    Marked as answer Smile

  • ad_handlers!!