Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Enabling Menu Toolstrip Items

Posted on 2007-11-14
13
Medium Priority
?
1,409 Views
Last Modified: 2008-02-01
I have a toolstrip that, by default, has a number of items disabled. I have a database table that defines different functionalities that a user is allowed in the application. Upon starting my application, I am reading that table, based on the UserName and returns a collection of permissible actions.

I am trying to figure out how to iterate through the collection and enable the appropriate menu items. I was thinking of associating the Tag of the individual menu items with the role, and iterating through the menu items for a tag that matches the role, but that seems like a lot of overhead. There will be different paths on the toolstrip that will be affected by this (for example, items under Tools, and subitems under those items, items under Reports, etc.

Some suggestions from the experts? I could map to the toolstrip item name, but that makes the data in the database table seem cryptic.
0
Comment
Question by:dbbishop
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 20283893
After the login/password autentication I enable the toolstripitens that as special access. Normally I define in the database the access level like 9 = administrator; 1 = user ...

Then on the form load I enable the menuitens that I want.
0
 
LVL 15

Author Comment

by:dbbishop
ID: 20284034
There would be too many permutations. Coding would be a nightmare. I have 5-6 top level menu items, sub items, sub-sub items, etc. One user might have access to only. As this grows, there could be 15 Items that could be enabled at startup, which means 1,307,674,368,000 permutations. It is a lot easier to just access a subset of those 15 items and enable the appropriate items.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 20284130
What is your datatable structure. Do you have a field for every menuitem?

Goran
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:Priest04
ID: 20284135
sorry, database table, bot datatable. :)

Goran
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20284152
Hi have, in most of my applications, a special menu (hidden by default) for administration. Also for the supervisors I have disabled items that I enable in the start up (just some).

Do you have so many options ?
0
 
LVL 15

Author Comment

by:dbbishop
ID: 20284260
>> Do you have so many options ?
Yes, because, for example, there will be some reports that are only accessible to certain users. The tools menu will be the same, as will the administration menu. There will be way too many permutations to assign 'roles'.

>> Do you have a field for every menuitem?
Not every one, but a lot of them. Currently 6, and the application is young. And that doesn't include any reports.

I am thinking of wrapping this in a SELECT statement, and depending on the value returned (CASE), find and enable the appropriate menuitem.
0
 
LVL 1

Expert Comment

by:aperion
ID: 20284743
Is adding a boolean field for every object (MenuItem, Report, Page, etc.)  you want that user to see out of the question?  Then you can make one database call and assign the visible property equal to the boolean value of the field for that user.  For example, If I have a website with a menu with three items...(Users, Admin, Supervisors), then when a user logs in they may or may not be able to view links with the right permissions assigned.
0
 
LVL 15

Accepted Solution

by:
dbbishop earned 0 total points
ID: 20284896
I added a column to the database table that contains the menu item name and return it instead of a 'role' associated with that menu item. That way, I just iterate through the collection that is returned and using the code:

        For idx = 0 To LoginCheck.AccessModules.Length - 1
            ms = Me.MenuStrip.Items.Find(LoginCheck.AccessModules(idx), True)
            ms(0).Enabled = True
        Next

I'll probably add error handling just in case I try to enable a non-existing menu item, but that shouldn't happen unless someone gets itchy fingers in the database.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 20285026
maybe you could shorten your code by doing next:

1) have all columns in database table have names like toolstripmenuitems do
1) get data in datatable
2) loop through all columns, get column name, and find menuitem with this column name
3) set visible for this item to column value

Goran
0
 
LVL 15

Author Comment

by:dbbishop
ID: 20285755
Priest04: Did I miss something? That is what I said I did.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 20285854
If you are referring to your last post, then I didn't see that one. If you want to use "per user" settings, thats the fastest it can be.

Goran
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20311881
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month6 days, 15 hours left to enroll

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question