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.

Preventing cell edits after delete key press

Thread ID:

Created:

Updated:

Platform:

Replies:

65369 Jul 25,2007 09:59 PM Sep 23,2013 09:43 AM Windows Forms 10
loading
Tags: GridControl
Ben Fraser
Asked On July 25, 2007 09:59 PM

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

Rajagopal [Syncfusion]
Replied On July 27, 2007 09:59 PM

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

Ben Fraser
Replied On July 29, 2007 06:46 PM

Great! Exactly what I needed. Thanks.

Ben Fraser
Replied On July 29, 2007 08:26 PM

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

Administrator [Syncfusion]
Replied On July 30, 2007 09:03 AM

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.

Ben Fraser
Replied On July 30, 2007 08:55 PM

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

Administrator [Syncfusion]
Replied On July 31, 2007 05:26 AM

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

Ben Fraser
Replied On July 31, 2007 07:17 PM

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

Administrator [Syncfusion]
Replied On August 1, 2007 02:18 AM

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
}


Ben Fraser
Replied On August 1, 2007 07:39 PM

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

Thanks for your help.

Sandeep
Replied On September 23, 2013 09:43 AM

its working!

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.

;