472,119 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Disable MenuItem Shortcut


the application I am writing has a MainMenu and a DataGrid

Now I have to edit the text of each cell in this grid. So far so good.
All works fine in editmode but if I press a key which is also a
shortcut it doesn´t work and the menuitem-clickevent will be

KeyPreview of each parent form and each mdiparent is disabled.

For example: There is a shortcut in the menu which will be called by
pressing the delete key. If I am in editmode of a cell and I press
this key the shortcut should not be called but the text in this cell
should be edited.

So I tried to remove the shortcut like following code of my own
datagrid (inherits UltragGrid respectively DataGrid):

**** CODE ****
/// <summary>
/// Disable all shortcuts in all superior forms
/// </summary>
/// <param name="oShortcut">The shortcut which has to be
public void DisableFrmShorcut(Shortcut oShortcut)
//Find parent form
Control oControl = this.Parent;
while(!(oControl is frmEnhanced))
oControl = oControl.Parent;
while(oControl != null)
for(int i = 0; i <((frmEnhanced)oControl).Menu.MenuItems.Count; i++)
//Find an remove all shortcut which is equal oShortcut
this.RemoveMenuShortcuts(((frmEnhanced)oControl).M enu.MenuItems[i],oShortcut);
//Is there another superior form (maybe mdiparent)
oControl = oControl.Parent;
while(!(oControl is frmEnhanced) && oControl != null)
oControl = oControl.Parent;
/// <summary>
/// Search every subordinate menuitem and disable the shortcut
/// </summary>
/// <param name="oItem"></param>
/// <param name="oShortcut">The shortcut which has to be
private void RemoveMenuShortcuts(MenuItem oItem,Shortcut oShortcut)
for(int i = 0; i < oItem.MenuItems.Count;i++)
//recursive call of this method to find all menuitems
if(oItem.Shortcut == oShortcut)
//Remove Shortcut ans disable menuitem
oItem.Shortcut = Shortcut.None;
oItem.Enabled = false;
//Remember all disabled shortcuts
**** CODE END ****

When I am entering the editmode of each cell I call the first methode
above to disable the shortcuts. This works fine and the menuitem(s)
are disabled and the shortcuts arent displayed in the menu but the
menuitem-clickevent will be performed again and agian.

Does anyone have an idea how I can resolve this problem??? I would be
very glad if someone can help me!

Best regards

Marcel Stallmach

hope you understand my english and what I mean ;)
Nov 16 '05 #1
0 2608

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Lex | last post: by
6 posts views Thread by Claus Holm | last post: by
3 posts views Thread by Stilgar[bbs.isca.uiowa.edu] | last post: by
5 posts views Thread by Brian Henry | last post: by
reply views Thread by Locusta | last post: by
1 post views Thread by inadsad | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.