Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on click eventHandler for dynamic menus

Status
Not open for further replies.

phinoppix

Programmer
Jul 24, 2002
437
US
Menus are added and removed based on an xml definition. Each menu item has a unique Id. I group the menus into groups (the main menu, eg File group, Edit group) so that each group has its own Click eventhandler.

1) Is there a way to save the Id to a menuitem's prop so I can retrieve this later via eventhandler params?

2) I'm thinking of overriding the GetHashCode() to return the unique Id instead. Is this possible? necessary? If not, any suggestions?

Tnx
 
Hi,
1. You have to implement your own MenuItem class derived from MenuItem in which you can store additional information and that info will be accessible via event handler params.
If you want to draw dynamic menus you have to provide a DrawItemEventhandler and a MeasureItemEventHandler as well a EventHandler when the menu item is Clicked.


private void menuItemDynamicMenu_Click(object sender, System.EventArgs e)
{
MyMenuItem mi = (MyMenuItem)sender;
switch (mi.m_ID)
{
case "101":
break;
case "102":
break;
...
}

}

2. Yes, you can override the GetHashCode() function but there are some rules.
3. Another solution is to store the ID in Hashtable (key->value) where the key will be generated from the menuGroup string + menuitem string and the value will be the "id=" retrieved from the XML file.
e.g. the menu group string + menu item string are unique.
When you click a menuitem you know which group belongs it and also MenuItem.Text - should be unique in your application.

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top