Solved

AND  between 2 integers

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

14 Experts available now in Live!

Get 1:1 Help Now