Solved

AND  between 2 integers

Posted on 2006-11-12
5
260 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now