Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/04/2010, 11:07
codeando
 
Fecha de Ingreso: abril-2010
Mensajes: 4
Antigüedad: 14 años
Puntos: 0
Pregunta MenuStrip dinamico desde SQL alguien me da la mano [Urgente]

Fíjense que me he estado dando duro con eso que no puedo lograr alguien es tan amable o si tiene algún ejemplo sobre como crear en un form un menustrip desde alguna base de datos mysql. fíjense que cree una clase que me hace la consulta pero no me genera el menú suponiendo tengo un archivo de clase:

Código:
Public Function GenerarMenu(ByVal flag As Boolean, ByVal usuario As String, ByVal ip As Integer, ByVal opc As MainMenu.MenuItemCollection) As System.Windows.Forms.MainMenu
        Dim tabla As DataTable
        Dim mMenu As MenuItem
        If flag = True Then
           tabla = ObOp.Consultar("select idopc, cnomopc,caccion,cdescripcion from menu where cgrp='admin'))")
        End If
        Dim dvArbol As DataView
        dvArbol = New DataView(tabla)
        dvArbol.RowFilter = tabla.Columns(3).ColumnName + "=" + ip.ToString
        For Each dractual As DataRowView In dvArbol
            Dim t As New MenuItem
            t.Name = dractual.Item(0)
            t.Text = dractual.Item(1)
            t.Tag = dractual.Item(2)
            If opc Is Nothing Then
                mMenu.MenuItems.Add(t)
            Else
                opc.Add(t)
                AddHandler t.Click, AddressOf opciones_click
            End If
            GenerarMenu(False, usuario, t.Name, t.MenuItems)
        Next dractual
        Return GenerarMenu
    End Function
 Private Sub opciones_click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim t As MenuItem
        t = CType(sender, MenuItem)
        Dim formulario As New Form
        Dim tipo As System.Type
        If t.Text = "sasSalir" Then
            form_login.Close()
        Else
            Try
                tipo = Type.GetType("ADUS." & t.Tag)
                formulario.Show()
            Catch ex As Exception
                MessageBox.Show("El programa no existe")
            End Try
        End If
    End Sub
Entonces en mi formulario principal hago una prueba llamando directamente el método así:
Código:
Call mUsr.GenerarMenu(True, 1, 1, Nothing)
Mi formulario es este:

Código:
Public Class MenuUsuario
    Inherits System.Windows.Forms.Form
    Public usuario As String
    Private mUsr As New clsClasedeArriba
    Private Sub Menu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If usuario Is Nothing Then
            'vacio
        Else
            'Probando el numero 1
            Call mUsr.GenerarMenu(True, 1, 1, Nothing)
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
        form_login.Close()
    End Sub
End Class
Pero al ejecutarlo el formulario no me muestra el menú debo hacer algo mas? tienen algún ejemplito. Gracias!