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 ;)