469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Disable MenuItem Shortcut

Hi,

the application I am writing has a MainMenu and a DataGrid
(UltraGrid).

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
performed.

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
disabled</param>
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
disabled</param>
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
this.RemoveMenuShortcuts(oItem.MenuItems[i],oShortcut);
}
if(oItem.Shortcut == oShortcut)
{
//Remove Shortcut ans disable menuitem
oItem.Shortcut = Shortcut.None;
oItem.Enabled = false;
//Remember all disabled shortcuts
this._aDisabledShortcuts.Add(oShortcut);
}
}
**** 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 2446

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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.