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.

In GridControl how to override "DEL" key behavior?

Thread ID:

Created:

Updated:

Platform:

Replies:

23008 Jan 2,2005 08:19 AM Jan 31,2005 06:48 AM Windows Forms 5
loading
Tags: GridControl
Rebecca
Asked On January 2, 2005 08:19 AM

when click the column header and press "DEL" key, the whole data in this colum is cleared, including column header text. I want to customize DEL behavior and using "Key Down" event, but it seems it does "my task" and then does the GridControl-defined task. So the whole column is still cleared . What can I do? Thanks!

Administrator [Syncfusion]
Replied On January 2, 2005 11:36 AM

You can use the CellClearing event. Here is an event sample that clears any cell other than teh header cells.
private void gridControl1_ClearingCells(object sender, GridClearingCellsEventArgs e)
{
	foreach(GridRangeInfo range in e.RangeList)
	{
		GridRangeInfo r = range.ExpandRange(1, 1, gridControl1.RowCount, gridControl1.ColCount);

		this.gridControl1.ChangeCells(r, "");
	}
	e.Handled = true;
	e.Result = true;
}

Administrator [Syncfusion]
Replied On January 29, 2005 05:08 AM

Thanks for your reply! When I click "DEL" key in a TextBox cell, it clears the value and then goes to "KeyDown" event, when KeyCode is recognized as "Menu". ClearingCells event is never fired. Could you tell me how to avoid the "clear cells" behavior performed by the Form itself? PS, I know that in GDBG, there''s a property "EnableRemove" which could shield the "clearing" event. >You can use the CellClearing event. Here is an event sample that clears any cell other than teh header cells. > >
>private void gridControl1_ClearingCells(object sender, GridClearingCellsEventArgs e)
>{
>	foreach(GridRangeInfo range in e.RangeList)
>	{
>		GridRangeInfo r = range.ExpandRange(1, 1, gridControl1.RowCount, gridControl1.ColCount);
>
>		this.gridControl1.ChangeCells(r, "");
>	}
>	e.Handled = true;
>	e.Result = true;
>}
>

Administrator [Syncfusion]
Replied On January 29, 2005 06:12 AM

The above code should work if you click a header cell and press Del provided Del is not a menu hot key. If you need to catch a Del key that is a menu hot key, you will have to derive the grid and override ProcessCmdKey.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
	if(keyData == Keys.Delete)
	{
		return false;
	}
	return base.ProcessCmdKey (ref msg, keyData);
}

Rebecca
Replied On January 31, 2005 06:14 AM

hi, ProcessCmdKey() does catch the "DEL" before it handles menu action, but I think it should return "true" in order to indicate this key is processed and there''s no need for system to handle it. Before "return true", I can introduce my own DoDelete() method. Please be kind to tell me whether I am right. I find in other forums that overriding IsInputKey()and OnKeyDown(), but I fail to run it correctly. Could you give some advice? Sorry that this may beyond your charge :-) Thanks & Regards

Administrator [Syncfusion]
Replied On January 31, 2005 06:48 AM

With respect to ProcessCmdKey, as far as avoiding a menu handler getting the command key, I think not calling the baseclass is the main thing that needs to be done. Return false or true depending upon whether you want the control itself to further process the key. The help suggests to me that IsInputKey controls whether a key is subject to preprocessing which I would guess (don''t know) it means you could catch it in a PreProcessMessage override.

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.

;