We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Popup menu and grid key command handling

Hello there, I have a grid with a popupmenu associated with it. One of the commands in the popupmenu has a shortcut key - the delete key. This is so I can perform some custom processing when the user presses delete -- I wish to delete the entire current row out of the grid. However my problem is that when a cell is in edit mode I want the delete key to just delete the current character in that cell, ie. the normal grid processing for that key. The popupmenu is appearing regardless of whether the cell is in edit mode or not (as would be expected). How do I change this behaviour so that the delete key works in the grid cell when in edit mode and yet brings up the popupmenu when a cell is not in edit mode ? Thankyou, Shane.

3 Replies

SH Shane July 13, 2004 08:55 PM

Sorry that last part should have read "and yet fires the popupmenu command when a cell is not in edit mode." > >Hello there, > >I have a grid with a popupmenu associated with it. One of the commands in the popupmenu has a shortcut key - the delete key. This is so I can perform some custom processing when the user presses delete -- I wish to delete the entire current row out of the grid. > >However my problem is that when a cell is in edit mode I want the delete key to just delete the current character in that cell, ie. the normal grid processing for that key. The popupmenu is appearing regardless of whether the cell is in edit mode or not (as would be expected). How do I change this behaviour so that the delete key works in the grid cell when in edit mode and yet brings up the popupmenu when a cell is not in edit mode ? > >Thankyou, > >Shane. >


AD Administrator Syncfusion Team July 14, 2004 01:45 AM

Here is one way you can get this to work for standard TextBox cells. In your menuhandler, only perform your action if there is not a currently editing cell. Then also handle the CurrentCellControlKeyMessage event, and in that event, handle the delete key for the editing currentcell yourself.
private void menuItem1_Click(object sender, EventArgs e)
{
	if(!this.gridDataBoundGrid1.CurrentCell.IsEditing)
	{
		Console.WriteLine("menuItem1_Click");
	}
}

private void gridDataBoundGrid1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
{
	Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;
	if(keyCode == Keys.Delete)
	{
		Console.WriteLine("gridDataBoundGrid1_CurrentCellControlKeyMessage");
		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
		GridTextBoxControl tb = cc.Renderer.Control as GridTextBoxControl;
		if(tb != null)
		{
			if(tb.SelectionLength == 0)
				tb.SelectionLength = 1;
			tb.SelectedText = "";
			e.Handled = true;
			e.Result = true;
		}
	}
}


SH Shane July 14, 2004 05:13 PM

Thankyou Clay, thats all I needed to get out of trouble. >Here is one way you can get this to work for standard TextBox cells. > >In your menuhandler, only perform your action if there is not a currently editing cell. Then also handle the CurrentCellControlKeyMessage event, and in that event, handle the delete key for the editing currentcell yourself. > >
>private void menuItem1_Click(object sender, EventArgs e)
>{
>	if(!this.gridDataBoundGrid1.CurrentCell.IsEditing)
>	{
>		Console.WriteLine("menuItem1_Click");
>	}
>}
>
>private void gridDataBoundGrid1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
>{
>	Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;
>	if(keyCode == Keys.Delete)
>	{
>		Console.WriteLine("gridDataBoundGrid1_CurrentCellControlKeyMessage");
>		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
>		GridTextBoxControl tb = cc.Renderer.Control as GridTextBoxControl;
>		if(tb != null)
>		{
>			if(tb.SelectionLength == 0)
>				tb.SelectionLength = 1;
>			tb.SelectedText = "";
>			e.Handled = true;
>			e.Result = true;
>		}
>	}
>}
>

Loader.
Live Chat Icon For mobile
Up arrow icon