Skip to content

How to disable context menu item

Suraj Rai

Asked Jan 24, 2007, 3:48 AM EST1 answer
Share
LinkedInX

Hi,

   I have one context menu having some item. What I need is

suppose the Item in listview is not selected then some of the context menu item should be disable. Say delete  or Rename should be disable.

My code is like this :


private void lvwShortCuts_MouseDown(object sender, MouseEventArgs e)
        {
            if (lvwShortCuts.SelectedItems.Count > 0)
            {
                PropertyMenu = new ContextMenu();

                PropertyMenu.MenuItems.Add("Rename", new EventHandler(popup));

                PropertyMenu.MenuItems.Add("Delete", new EventHandler(popup));


                this.ContextMenu = PropertyMenu;
            }
        }
        private void popup(object sender, EventArgs e)
        {

            MenuItem miClicked = (MenuItem)sender;

            string item = miClicked.Text;

            if (item == "Rename")
            {
               
                if (lvwShortCuts.SelectedItems.Count > 0)
                {
                    this.lvwShortCuts.SelectedItems[0].BeginEdit();
                }
                if (item == "Delete")
                {
                                  
                }
            }
        }


How to get the context menu item disable.
Thank You.....
Suraj

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    Use MenuItem.Enabled = false;
    MenuItem is the item you want to disable.
    0