show menu items on application based on user rights

Hi all,i'm trying to show menu items based on user rights.. I'm using database to store the menu names and the user position like this

position menu
admin mnuUser
admin mnuEmployee

I named the ToolStripMenuItem items name to mnuxxxx.Suppose it was the admin who logged in,then the menu items like mnuUser,mnuEmployee will be visible..Else they won't be visible..I've created the menu items names based on the mnuxxxx ..How should i achieve it??Thanks a lot...


  • Good day....i have never stored menu items in a database but what i usually do is create multiple forms that cater for each role and the menu you want them to have access to. when ever they log in, the form assigned to their role pops up.
    What do you think????
  • seancampbellseancampbell Pennsylvania, USA
    Handoyo, you mind posting a little bit more information about the solution you figured out?

    I was going to write a post today about filtering the data and only putting subitems into the ListView that you needed to show, but if you found a way to hide line items I'd love to see that solution as I have no experience with it!!

    Thanks in advance,
    Sean Campbell forum mod
  • Hi Sean,i found the solution at here

    I use the codes that are posted by Snip..Here are the codes

    Private Function SetMenuItem(ByVal name As String, ByVal enabled As Boolean)

    Dim m As ToolStripMenuItem

    m = Me.FindToolStripMenuItem(Me.MenuStrip1.Items, name)

    If m IsNot Nothing Then

    m.Enabled = enabled

    Return True


    Return False

    End If

    End Function

    Private Function FindToolStripMenuItem(ByRef menus As ToolStripItemCollection, ByVal name As String) As ToolStripMenuItem

    Dim found As Boolean = False

    Dim t, temp As ToolStripMenuItem

    t = menus(name)

    If t Is Nothing Then

    Dim i As Integer = 0

    While Not found And i < menus.Count

    If menus(i).GetType Is GetType(ToolStripMenuItem) Then

    temp = menus(i)

    t = Me.FindToolStripMenuItem(temp.DropDownItems, name)

    found = (t IsNot Nothing)

    End If

    i += 1

    End While

    End If

    Return t

    End Function


    But it was used to set ToolStripMenuItem.visible=true.. ^_^
  • seancampbellseancampbell Pennsylvania, USA
    Ohhhhh, I thought we were talking about a List View for some reason, dooooh. Thanks again for the information, good to have as much sample code floating around as possible ^_^

    Take cAre,
    Sean Campbell -
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!