This is a migrated thread and some comments may be shown as answers.

Cancel edit for the current cell

11 Answers 399 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nathaniel
Top achievements
Rank 1
Nathaniel asked on 25 Jan 2012, 07:17 PM
How do I cancel editing of the current cell in a radgridview in the code behind.  I want the same behavior as if I had hit the escape key once. 

11 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 Jan 2012, 07:57 AM
Hi,

 Have you tried CancelEdit() method of the grid?

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nathaniel
Top achievements
Rank 1
answered on 26 Jan 2012, 01:14 PM
CancelEdit cancels the edit of the entire row in the grid.  CancelEdit is the same behavior as hitting escape twice, i just want to cancel edit on the current cell.
0
Nedyalko Nikolov
Telerik team
answered on 26 Jan 2012, 04:47 PM
Hello,

Could you please provide me with a little bit more information about your scenario and what are you trying to achieve?
Thank you in advance.

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nathaniel
Top achievements
Rank 1
answered on 26 Jan 2012, 05:17 PM
Here is my scenrario.  For a column I have it's CellEditTemplate using a combox.  In the section changed event for that combox I have some logic that evaluates the current section, and depending on the choice prompts the user if they are sure they want to make this change.  If the user says no, then I want to call cancel edit on the current cell.  Because there is no cancel edit for the current cell, I have to manually set the value back to what is was before the user started editing that cell. 

0
Nedyalko Nikolov
Telerik team
answered on 30 Jan 2012, 12:37 PM
Hello,

We will consider adding a public API for "Cancel cell edit", meanwhile you could execute RadGridViewCommand.CancelCellEdit command via code behind.

RadGridViewCommands.CancelCellEdit.Execute(null);

This will cancel edit of the current cell and it is what RadGridView performs when Esc key is pressed.
Let me know if this doesn't help.

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alan
Top achievements
Rank 2
answered on 28 Jun 2012, 09:51 PM
If possible could you give a small code example on how to invoke
RadGridViewCommands.CancelCellEdit.Execute(null);
against a radgridview object in C#?

Thank you,

0
Maya
Telerik team
answered on 29 Jun 2012, 06:33 AM
Hi Alan,

 
Could you take a look at this article ? Is that example you are looking for ? 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alan
Top achievements
Rank 2
answered on 29 Jun 2012, 01:11 PM
Thank you for the article.

When I try the following code:
RoutedUICommand cancelCellEdit = RadGridViewCommands.CancelCellEdit.Execute(null) as RoutedUICommand;
cancelCellEdit.Execute(null, this.radGridView);

I am getting a boxing and unboxing error at compile time. Is there some other kind of software pattern I need to use?

The compile time error:
Error    136    Cannot convert type 'void' to 'System.Windows.Input.RoutedUICommand' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion  

0
Maya
Telerik team
answered on 29 Jun 2012, 01:16 PM
Hello Alan,

Can you try defining your command as follows:

var cancelCellEdit = RadGridViewCommands.CancelCellEdit as RoutedUICommand;
cancelCellEdit.Execute(null, this.clubsGrid);
 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alan
Top achievements
Rank 2
answered on 29 Jun 2012, 01:23 PM
It is compiling thank you!

But the grid is tabbing to the next cell. Is there a way to invoke a command to prevent that as well?
0
Maya
Telerik team
answered on 29 Jun 2012, 01:28 PM
Hi,

What you can try is to set the cell whose editing you just cancelled and set it as current again. Will that approach meet your requirements ? 
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Nathaniel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Nathaniel
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Alan
Top achievements
Rank 2
Maya
Telerik team
Share this question
or