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

Preventing cell edits after delete key press

Hello,

I'm on 5.1 and using a Virtual grid.

I have selected a cell. The cell is not in edit mode. I hit the delete key. The cell contents are deleted and a cell edit is immediately started. I do not want to begin a cell edit at this point, I just want the cell contents to be deleted. How can I do this? I am already handling the CurrentCellDeleting event but that only allows me to cancel the delete altogether, not keep the delete and stop the edit.

Also, the Home key will start an edit. It should move the selected cell to the start of the row. The key seems to get handled internally by you guys somewhere and I never see it in the grids' KeyDown or KeyUp events so I cannot override this behaviour for myself.

The End key also begins an edit and doesn't come through the normal events. I want to prevent it from starting an edit.

Thanks,
Ben

10 Replies

RA Rajagopal Syncfusion Team July 28, 2007 01:59 AM UTC

Hi Ben,

Thanks for your interest in Syncfusion Products.

You could control all the key events inside the cell through the CurrentCellKeyDown event of the grid. Please try the code below in the CurrentCellKeyDown event handler, that will help you in achieving the intended behavior.

void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
GridCurrentCell cc = this.grid.CurrentCell;
if (e.KeyCode == Keys.Delete && !cc.IsEditing)
{
e.Handled = true;
cc.Renderer.ControlText = "";
cc.EndEdit();
}
else if (e.KeyCode == Keys.Home)
{
e.Handled = true;
cc.MoveTo(cc.RowIndex, 1);
}
else if (e.KeyCode == Keys.End)
{
e.Handled = true;
cc.MoveTo(cc.RowIndex, this.grid.ColCount);
}
}

Let me know if this helps.

Have a nice time.
Regards,
Rajagopal


BF Ben Fraser July 29, 2007 10:46 PM UTC

Great! Exactly what I needed. Thanks.


BF Ben Fraser July 30, 2007 12:26 AM UTC

Ummm OK maybe not quite.

After the delete I would like any dependent formula cells in my grid to update straight away. The cells will currently update only after the cell selection leaves the cell deleted.

Calling Reactivate on the cell doesn't work. Getting the FormulaCellModel from the grid and calling refresh range on the cell doesn't work.

What do I do here?

Thanks,
Ben


AD Administrator Syncfusion Team July 30, 2007 01:03 PM UTC

By default, formula cells are activated for editing as soon as they get focus. (This is how you see the formula string when you click on a cell). This default behavior sets cc.IsEditing earlier in the cell activation cycle than it is set for non FormulaCell celltypes and is causing the cc.IsEditing check in the delete key event handler code to ignore handling the Delete key for formula cells. So, the code is being skipped and the default delete key handling takes place.

Try setting this static member in your from.Load.

GridFormulaCellRenderer.ForceEditWhenActivated = false;

It turns off the automatic edit mode in formula cells and will allow your event handler to handle the delete key.


BF Ben Fraser July 31, 2007 12:55 AM UTC

Hello,

The ForceEditWhenActivated was already set in our product, its value does not alter the update behaviour I am seeing.

I've prepared a small sample of what I am doing in our product. I have included a number of other variables I am setting in our product in the LoadGridControlFormulasTest function in case one of them has some effect I am unaware of. The CurrentCellKeyDown event handler given in this thread is at the bottom of the GridControlFormulaTest.cs file.

To clarify what I am looking for, here is a set of steps to follow. My apologies if I am being to literal.
* start the sample
* select a cell with the mouse
* using the keyboard select cell B3 (this means we're not in cell edit mode)
* hit delete. The cell E3 is not updated.
* hit enter. The cell selection moves off B3 to C3, cell E3 is updated.

Regards,
Ben

GridControlFormulasTest.zip


AD Administrator Syncfusion Team July 31, 2007 09:26 AM UTC

If you want to see the changes immediately woithout leaving the cell, you will also have to call CurrentCell.ConfirmChanges.

For some reason, I cannot download your sample. But here is the sample I used. If you cursor into cell A1 and press Delete, you will see cell C1 update immediately without leaving cell A1.


WindowsApplication65.zip


BF Ben Fraser July 31, 2007 11:17 PM UTC

Hi,

OK, here's another attempt at posting the sample. The only difference between yours and mine is that I have a virtual grid control. This is no doubt the cause of the problem.

Cheers,
Ben

GridControlFormulasTest0.zip


AD Administrator Syncfusion Team August 1, 2007 06:18 AM UTC

In your sample, if I add cc.ConfirmChanges, things update immediately for me using 5.1.1.x.


if (e.KeyCode == Keys.Delete && !cc.IsEditing)
{
e.Handled = true;
cc.Renderer.ControlText = "";
cc.EndEdit();
cc.ConfirmChanges(); //<<<<<< added
}



BF Ben Fraser August 1, 2007 11:39 PM UTC

My apologies. I was dumb enough to put the ConfirmChanges before setting the control text. Naturally, that did not work.

Thanks for your help.


SA Sandeep September 23, 2013 01:43 PM UTC

its working!

Loader.
Live Chat Icon For mobile
Up arrow icon