Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake the items in a menu behave as a radio button group in Visual Basic .NET
DescriptionThis example shows how to make the items in a menu behave as a radio button group in Visual Basic .NET.
Keywordsoption button, menu, menu items, radio button, Visual Basic .NET, VB.NET
CategoriesControls
 
This example makes the items in a menu behave like a radio button group so when you select one, it displays a check mark and the others don't.

The key is the CheckMenuItem function.

This function takes as parameters a menu and a menu item. It loops through the objects contained in the menu. If an object is a menu item (e.g. not a separator or something else), the code sets its Checked property appropriately.

 
' Uncheck all menu items in this menu except checked_item.
Private Sub CheckMenuItem(ByVal mnu As ToolStripMenuItem, _
    ByVal checked_item As ToolStripMenuItem)
    ' Uncheck the menu items except checked_item.
    For Each item As ToolStripItem In mnu.DropDownItems
        If (TypeOf item Is ToolStripMenuItem) Then
            Dim menu_item As ToolStripMenuItem = _
                DirectCast(item, ToolStripMenuItem)
            menu_item.Checked = (menu_item Is checked_item)
        End If
    Next item
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated