VB.Net 2013... How to get the Dynamic Click event... The Menu are coming from Database..

  • Thread starter Thread starter Harish Waghmare
  • Start date Start date
H

Harish Waghmare

Guest
At the time of Form load all the menu are populating from the database... Its working fine but i am not getting the Click event of the Current selection

Private Sub MDI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim connString As String = ""
Dim pms As New MySqlParameter()
Dim cmd As New MySqlCommand
Dim Dgv1 As New MySqlConnection
Try
ErrPrvdr.Clear()
connString = GetDBConnection()

Dgv1 = New MySqlConnection(connString)
cmd.Connection = Dgv1
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "UserMenu"
cmd.Parameters.AddWithValue("_UserID", iUserID)
Dim sda As New MySqlDataAdapter(cmd)
Dim Dtset As New DataSet
sda.Fill(Dtset)

For i As Integer = 0 To Dtset.Tables(0).Rows.Count - 1
Dim item = New ToolStripMenuItem()
item.Name = Dtset.Tables(0).Rows(i)(0).ToString
Dim img() As Byte
img = Dtset.Tables(0).Rows(i)(1)
Dim ms As New MemoryStream(img)

Dim pic As Image = Image.FromStream(ms)
MenuStrip1.Items.Add(Dtset.Tables(0).Rows(i)(0), pic)

AddHandler MenuStrip1.Click, AddressOf ClickHandler
Next

Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
''MsgBox(iUserID)
End Sub



---------------


Public Sub ClickHandler(ByVal sender As Object, ByVal e As EventArgs)
'for a condition based on a ToolStripMenuItem that fired it

Dim item As ToolStripMenuItem = sender ' CType(sender, ToolStripMenuItem)

MsgBox(item.Text)




End Sub

Continue reading...
 
Back
Top