Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've got the following problem,
My application has a lot of (inheritance)forms, and to navigate those forms, i use one main form with a menustrip, that contains al the links.

And ofcourse this pricilpe principle works fine as long i don't mess with it.

But now the following problem arises, i need to make "users" in my program, that can log in etc.
And of course every "type" of user has rights, to what froms they have exces etc.

But how can i change the menustrip in the "mainform", to reflect te forms that the current user has acces to?


With kind regards,

a troubled guy

(and i know i can make multiple menustrips, and hide the ones not in use, but that, of course, won't do, becouse of the sheer ammount of rights)
Posted
Updated 1-Apr-11 2:39am
v2
Comments
Albin Abel 1-Apr-11 8:53am    
instead of multiple menu strips, have multiple validation methods which disable or hide menu elements. Just a suggestion. I am not sure about the complexity of your design
johannesnestler 1-Apr-11 9:03am    
Yes maybe possible but what if other (existing?) code disables/enables the MenuItems for some logical reason, this can be quite messy (see my other comment)
Albin Abel 1-Apr-11 9:11am    
Agreed. Alternatively if those menus are organized/ grouped well then implementing authorization would be easier. May be Original Griff's answer helps if the children from a top menu has different access privileges
johannesnestler 1-Apr-11 9:00am    
I solved a similar problem with a special MenuItem implementation. I just added an Authorization property to the MenuItem to control the enabled/visual states (independend from the logical states, don't make this mistake!). Then I just applied the current authorization information to all controls (kind of recursive). Make it an interface and implement it for all controls you want to protect with rights.

1 solution

Each menu strip item list can be changed when the user goes to open it: If you handle the ToolStripDropDownItem.DropDownOpening[^] event then you can set the rights dynamically when the user goes to access them. Then just disable or hide the inappropriate main menu list items.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-11 16:51pm    
Or add/remove -- big deal. A 5, anyway.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900