Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Disabling MenuItems

Disabling MenuItems

Scheduled Pinned Locked Moved C#
questiontutorial
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naglbitur
    wrote on last edited by
    #1

    Hi there. I have an app that has several menus. I want that when a certain menuItem(s) is/are selected other menuItems are disabled. For instance, if a user selects menuItem2 I want menuItems 10, 12 and 17 to be disabled. How do I go about coding that? I know about Enable = false but I don´t know how to code: if such and such menuItems are selected then such and such menuItems are to be disabled. Thanks, FJ

    D A 2 Replies Last reply
    0
    • N naglbitur

      Hi there. I have an app that has several menus. I want that when a certain menuItem(s) is/are selected other menuItems are disabled. For instance, if a user selects menuItem2 I want menuItems 10, 12 and 17 to be disabled. How do I go about coding that? I know about Enable = false but I don´t know how to code: if such and such menuItems are selected then such and such menuItems are to be disabled. Thanks, FJ

      D Offline
      D Offline
      dnewmon
      wrote on last edited by
      #2

      Are you talking about menu items with CheckBox's ? Something this simple might help: menuItem3.Enabled = (menuItem1.Checked && menuItem2.Checked && ...); Enjoy, David

      N 1 Reply Last reply
      0
      • D dnewmon

        Are you talking about menu items with CheckBox's ? Something this simple might help: menuItem3.Enabled = (menuItem1.Checked && menuItem2.Checked && ...); Enjoy, David

        N Offline
        N Offline
        naglbitur
        wrote on last edited by
        #3

        Hi. No, what I mean is to have a menuItem like Paste grayed out unless you have something on the clipboard, one can´t paste unless something is on the clipboard. Once you have something on the clipboard Paste becomces selectable, not grayed out. I want certain menuItems to be grayed out if some other menuItem is selected. Thanks, FJ

        M 1 Reply Last reply
        0
        • N naglbitur

          Hi. No, what I mean is to have a menuItem like Paste grayed out unless you have something on the clipboard, one can´t paste unless something is on the clipboard. Once you have something on the clipboard Paste becomces selectable, not grayed out. I want certain menuItems to be grayed out if some other menuItem is selected. Thanks, FJ

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          Hi! You can use the menu's Popup event to enable/disable the menu items of your menu, so if you have a menu myMenu you could write the Popup event handler like this:

          private void myMenu_Popup(object sender, EventArgs e)
          {
          myMenuItem1.Enabled = SomeFunctionToDecideWhetherMenuItem1IsEnabled();
          }

          or, using the clipboard example:

          private void menuEdit_Popup(object sender, EventArgs e)
          {
          DataObject dob = Clipboad.GetDataObjet();
          // Only enable the Paste command if there's Text on the clipboard
          menuEditPaste.Enabled = dob.GetDataPresent(DataFormats.Text);
          }

          Regards, mav

          N 1 Reply Last reply
          0
          • N naglbitur

            Hi there. I have an app that has several menus. I want that when a certain menuItem(s) is/are selected other menuItems are disabled. For instance, if a user selects menuItem2 I want menuItems 10, 12 and 17 to be disabled. How do I go about coding that? I know about Enable = false but I don´t know how to code: if such and such menuItems are selected then such and such menuItems are to be disabled. Thanks, FJ

            A Offline
            A Offline
            Andre Ziegler
            wrote on last edited by
            #5

            Search for an ActionList component on codeproject, this should help you. 'A programmer is just a tool which converts caffeine into code'

            1 Reply Last reply
            0
            • M mav northwind

              Hi! You can use the menu's Popup event to enable/disable the menu items of your menu, so if you have a menu myMenu you could write the Popup event handler like this:

              private void myMenu_Popup(object sender, EventArgs e)
              {
              myMenuItem1.Enabled = SomeFunctionToDecideWhetherMenuItem1IsEnabled();
              }

              or, using the clipboard example:

              private void menuEdit_Popup(object sender, EventArgs e)
              {
              DataObject dob = Clipboad.GetDataObjet();
              // Only enable the Paste command if there's Text on the clipboard
              menuEditPaste.Enabled = dob.GetDataPresent(DataFormats.Text);
              }

              Regards, mav

              N Offline
              N Offline
              naglbitur
              wrote on last edited by
              #6

              Hi, thanks for your help. I still don´t know how to do this. How can I disable a menuItem when some other menuItem is selected? For instance, if menuItem5 is chosen then I want menuItem11 and menuItem12 to be disabled? How do I do that? Thanks again for your help, FJ

              M 1 Reply Last reply
              0
              • N naglbitur

                Hi, thanks for your help. I still don´t know how to do this. How can I disable a menuItem when some other menuItem is selected? For instance, if menuItem5 is chosen then I want menuItem11 and menuItem12 to be disabled? How do I do that? Thanks again for your help, FJ

                M Offline
                M Offline
                mav northwind
                wrote on last edited by
                #7

                private void menuItem5_Clicked(object sender, EventArgs e)
                {
                menuItem11.Enabled = false;
                menuItem12.Enabled = false;
                }

                that's as explicit as I can put it... mav

                N 1 Reply Last reply
                0
                • M mav northwind

                  private void menuItem5_Clicked(object sender, EventArgs e)
                  {
                  menuItem11.Enabled = false;
                  menuItem12.Enabled = false;
                  }

                  that's as explicit as I can put it... mav

                  N Offline
                  N Offline
                  naglbitur
                  wrote on last edited by
                  #8

                  Hi. This is very clear!! Vielen Dank! Take care, FJ

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups