When a User logging into a WinForm (C#.net) application, how can i assign dynamically a defined Menu application according to a Data Base Role?
Thanks in advance for your support, time and for share your knowledge, it really helps.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jan MontanoRank #1,295 · 1.3K reputationPosted Jan 1, 2009, 8:27 PM EST
Normally, you predefine all menus needed by users. then upon logon, you hide/show/disable/enable menus based on the role of the user.
azariel moron18 reputationPosted Jan 2, 2009, 6:18 AM EST
Somebody has another idea? please i will apreciate it.
Jan MontanoRank #1,295 · 1.3K reputationPosted Jan 4, 2009, 1:12 AM EST
What in particular are you having trouble with?
1. Do you already have a database table with the roles?
2. Do you already know how to retrieve data from a database?
3. Have you already created menus in your application? What are the menus/submenus you created?
azariel moron18 reputationPosted Jan 4, 2009, 5:50 AM EST
Answer 1) Yes, i already have a database with the Roles and Users for each Role (SQL Server).
Answer 2) Yes, i already can retrieve data from the database.
Answer 3) Yes, i have created menus in my aplication, but there is only one menu, the main menu.
I want to differentiate (dinamically hide/show/disable/enable) the main menu depending on what user logging into my applitacion.
The menu has a menuStrip (with items) and a ToolStrip (with buttons).
Jan MontanoRank #1,295 · 1.3K reputationPosted Jan 4, 2009, 3:07 PM EST
my menu
---------
Admin (mnuAdmin)
-- adminsub1 (mnuAdminSub1)
-- adminsub2 (mnuAdminSub2)
Guest (mnuGuest)
-- guestsub1 (mnuGuestSub1)
-- guestsub2 (mnuGuestSub2)
PowerUser (mnuPowerUser)
-- powerusersub1 (mnuPowerUserSub1)
-- powerusersub2 (mnuPowerUserSub2)
something like this after calling the logon method.
----------------
Role role = logon(userid, password)
switch (role)
case role.Admin:
mnuGuest.Visible = false
mnuPowerUser.Visible = false
case role.PowerUser:
.....mnuPowerUserSub1.Enabled = false
you could also specifiy role funtions and which role are able to perform it in the database. you could then use that data to know which menus/submenus to disable/hide/enable/show
Hope this helps.