Solved

AND  between 2 integers

Posted on 2006-11-12
5
263 Views
Last Modified: 2010-04-16
Hi

I would like to create apermision sensitive menu. when the user logs on his system mermisions are loaded from a database. I then iterate through the menu options to see if the menuitem must be enabled or disabled. I wanted to do this by setting a value in the tag field of the menuitem at creation. If the iser option AND the tag field is true enable the menu.
The following code gives me an error. what is the correct way to do this.

        private void SetPermissions(MenuItem Menu, int PerValue)
            {
            foreach (MenuItem MI in Menu.MenuItems)
            {
                if (MI.MenuItems.Count > 0)
                    SetPermissions(MI, PerValue);

                if (MI.Tag != null)
                {
                    int TagValue = MI.Tag == null ? 0 : Convert.ToInt32(MI.Tag);

                    if ((TagValue & PerValue))
                        MI.Enabled = true;
                    else
                        MI.Enabled = false;
                }
            }
            }

Thanks
0
Comment
Question by:tcss
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 125 total points
ID: 17926240
I imagine that the error is that you can't implicitly convert the type int to a bool

Try this

if ((TagValue & PerValue)!=0)
0
 
LVL 1

Author Comment

by:tcss
ID: 17926294
Nice to have my question answered by a fellow countryman.
Gauteng
Centurion
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17926309
Nice to know that I am not the only South African on EE tonight. I thought that most of the others would have slunk off and hidden away after the rugby this weekend.
0
 
LVL 1

Author Comment

by:tcss
ID: 17926363
No comment. Will not embarrass myself on a public forum. :-)
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17926381
lol
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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