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
close icon

In GridControl how to override "DEL" key behavior?

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!

5 Replies

AD Administrator Syncfusion Team January 2, 2005 04:36 PM UTC

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


AD Administrator Syncfusion Team January 29, 2005 10:08 AM UTC

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


AD Administrator Syncfusion Team January 29, 2005 11:12 AM UTC

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


RE Rebecca January 31, 2005 11:14 AM UTC

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


AD Administrator Syncfusion Team January 31, 2005 11:48 AM UTC

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.

Loader.
Live Chat Icon For mobile
Up arrow icon