Jump to content

show menu items on vb.net application based on user rights

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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 submenu 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...

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
so you have
 position       menu
    admin       mnuUser
    admin       mnuEmployee
which is a menu and you want it to change to a different menu if a admin or something logs in right?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Yes i have those menu created already..I want the menu shown based on the user rights on that table..Thanks...

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
OK this should answer your question.:)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MenuStrip2.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MenuStrip2.Show()
        MenuStrip1.Hide()
    End Sub
OK so I have two menustrips, now when the form loads the second one is hidden and the first one is shown then if the button(in your case if your logged in) is clicked then show menustrip2 and hide menustrip1.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Well,actually i'm trying to show the menu based on the string from the database..I named the ToolStripMenuItem to mnuUser etc..I can't figured out how to do it.. :crying:

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Could you use a variable instead? let say when the admin logs in you set a variable adminloggedin to true, then instead of button click test if that variable is true then menu1.Hide() and menu2.Show(). Get what I'm saying?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
I get it..Thanks a lot... :)

#8
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
No problem.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.