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.
Unfortunately, activation email could not send to your email. Please try again.

Popup menu and grid key command handling

Thread ID:

Created:

Updated:

Platform:

Replies:

16374 Jul 13,2004 07:26 PM Jul 14,2004 05:13 PM Windows Forms 3
loading
Tags: GridControl
Shane
Asked On July 13, 2004 07:26 PM

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.

Shane
Replied On 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. >

Administrator [Syncfusion]
Replied On 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;
		}
	}
}

Shane
Replied On 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;
>		}
>	}
>}
>

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;