How to disable menu items?

I am having a problem with Menu . I am adding MenuItem to asp.net . I am using c# . I want to disable the Parents and Children menu with user permission. There are 3 users who are "User", "Power-User" and "BT_User". "User" has the worst resolution, and "BT_User" is the best.

How can i do this? Can anyone answer me?

+4
source share
3 answers

Implement your logic from here.

  if(UserType == "Power-User") { MenuItem mnuItem = Menu1.FindItem("MenuOption"); // If delete a specific item //to remove Menu1.Items.Remove(mnuItem); //to disable and not remove mnuItem.Enabled = false; } if (UserType == "BT_User") { Your other logic } 
+3
source

Just use the Enabled property for MenuItem . There is not enough information to tell you how to build logic around it, but if you want to disable it, just do this:

 menuItem.Enabled = false; 

It should be noted that you will not need to continue to disconnect any children when you disconnect a parent, because with Enabled set to false he is not allowed to fly out of any children.

From the MSDN documentation for the Enabled property:

Gets or sets a value indicating whether the MenuItem object is enabled, allowing the item to display a pop-up image and any child menu items.

0
source

try it

  if (UserType == "Power-User") { Menu1.Items.Find("MenuToDelete1", true)[0].Enabled = false; Menu1.Items.Find("MenuToDelete2", true)[0].Enabled = false; //or Menu1.Items.Remove(Menu1.FindItem("MenuToDelete")); Menu1.Items.Remove(Menu1.FindItem("MenuToDelete2")); } if (UserType == "BT_User") { Menu1.Items.Find("DeletedItem1", true)[0].Enabled = true; Menu1.Items.Find("DeletedItem2", true)[0].Enabled = true; MenuItem item1 = new MenuItem(); item.Text = "DeletedItem1"; MenuItem item2 = new MenuItem(); item.Text = "DeletedItem2"; //or menuStrip1.Items.Insert(index1, item1); menuStrip1.Items.Insert(index2, item2); } 
0
source

Source: https://habr.com/ru/post/1487313/


All Articles