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)
if (MI.Tag != null)
int TagValue = MI.Tag == null ? 0 : Convert.ToInt32(MI.Tag);
if ((TagValue & PerValue))
MI.Enabled = true;
MI.Enabled = false;