Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AND  between 2 integers

Posted on 2006-11-12
5
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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