Results 1 to 6 of 6

Thread: [RESOLVED] Adding a check box to a menu

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Bristol/Bath
    Posts
    85

    Resolved [RESOLVED] Adding a check box to a menu

    How do you make a menu item checkable? I have dragged the Main Menu onto my form and created an options menu, within that i want some of the items to be checkable. I tried dragging a checkbox onto the menu item, but that didnt work
    VS.Net Pro 2003, .NET 1.1

    My Photography portfolio:
    http://www.ephotozine.com/user.cfm?user=24834

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Adding a check box to a menu

    Open the property window after selecting the menuitem in the design mode and set the Checked property to True.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Adding a check box to a menu

    If you're using the MainMenu I assume that you're using .NET 1.x (please specify in future). Setting the Checked property of the menu item in the designer will make it appear checked but it doesn't help you at run time. You should double click the menu item to create a Click event handler and then add code like this:
    VB Code:
    1. Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
    2.     Dim item As MenuItem = DirectCast(sender, MenuItem)
    3.  
    4.     item.Checked = Not item.Checked
    5. End Sub
    This will toggle the check mark each time you click the menu item. By casting the sender as I have done you could use the same event handler for multiple menu items. If you're just using it for one you could hard code the name of the menu item rather than using a cast.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: [RESOLVED] Adding a check box to a menu

    Using the Menu's properties, you could also add a dot (like a radiobutton) - RadioCheck to your menu items, if desired....
    VB.NET MVP 2008 - Present

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Adding a check box to a menu

    Quote Originally Posted by HanneSThEGreaT
    Using the Menu's properties, you could also add a dot (like a radiobutton) - RadioCheck to your menu items, if desired....
    RadioCheck doesn't actually affect the checking of the item. It just displays a dot instead of a tick when the Checked property is True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: [RESOLVED] Adding a check box to a menu

    Quote Originally Posted by jmcilhinney
    RadioCheck doesn't actually affect the checking of the item. It just displays a dot instead of a tick when the Checked property is True.
    I never said it effects the checking of the item
    I just mentioned that it is also possible to add a dot in front of a menu item.
    VB.NET MVP 2008 - Present

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width