I need to develop a Winforms application where users are given permissions to access menu-items in a menu-strip as assigned to them.
I have anticipated the following technique:
(1) Menu Strip is mapped into a corresponding treeView with checkBoxes,
(2) A user is selected from the combo-box,
(3) Some tree-view-node check-boxes are checked in treeView to indicate that, “this user would be able to access these menu-items”,
(3) A save button is pressed to save the checked tree-Nodes and the user in the DB.
At later stages, when a user logs into the system, Menu-Strip items are populated accordingly from the DB.
Can anyone suggest me any better technique?
We have a similar implementation at work. This is a pretty straightforward design and works well.
You may want to add a unique identifier to each MenuItem. This can be as simple as:
And you include this number in the database. Then, when you write out the menu items, you can have a dictionary that maps the MenuItems integer to a delegate (for handling the execute event):
And somewhere define the mappings:
So that when you hookup the menu item event handlers, you can call the right method to perform the right action:
(Something to that effect, I probably have the syntax off slightly)
Update:
The “Tag” property of the tree-view item control gets populated like this, following the example above:
Then, when looking for what to write out: