Hi,
This functionality is not automatic. (Assuming you are referring to VS
2003, .NET 1.1)
Might be many ways to do it. Manually or Cleverly...
Here's my way : (The manual way)
--------------------------------------------
// This method is wired to Click events of all the MenuItems.
private void AllMnus_Click(object sender, System.EventArgs e)
{
MenuItem mnu = (MenuItem)sender;
Checker(mnu);
switch (mnu.Text)
{
case "One":
// Do your stuff
break;
case "Two":
// Do double the stuff
break;
case "Three":
// Do double the stuff
break;
}
}
// Iterates through the MenuItems, first unchecking all of them, and
then checking
// the relevant one.
private void Checker(MenuItem mnu)
{
foreach (MenuItem eachMnu in mnuTest.MenuItems)
{
eachMnu.Checked = false;
}
mnu.Checked = true;
}
--------------------------------------------
Explanation : Since the MenuItems have no Tag property (and
surprisingly, no Name property as well), we have to check the Text
property to find out which one was clicked. Then we just uncheck all of
them and check the proper one.
The Clever way :
An excellent alternative to doing it manually, might be to use Mick
Doherty's implementation. He uses an Extender component to add a Tag
property to MenuItems, and also a RadioGroup property which
accomplishes what we need. He should call it "Killing two birds with
one stone !" ;-)
This latter is the method I would recommend to you. Check out
<
http://www.dotnetrix.pwp.blueyonder.co.uk/menus.html>
Regards,
Cerebrus.