Cancel edit for the current cell

12 posts, 0 answers
  1. Nathaniel
    Nathaniel avatar
    68 posts
    Member since:
    Nov 2010

    Posted 25 Jan 2012 Link to this post

    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. 

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Jan 2012 Link to this post

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

  3. DevCraft banner
  4. Nathaniel
    Nathaniel avatar
    68 posts
    Member since:
    Nov 2010

    Posted 26 Jan 2012 Link to this post

    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.
  5. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 26 Jan 2012 Link to this post

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

  6. Nathaniel
    Nathaniel avatar
    68 posts
    Member since:
    Nov 2010

    Posted 26 Jan 2012 Link to this post

    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. 

  7. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 30 Jan 2012 Link to this post

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

  8. Alan
    Alan avatar
    32 posts
    Member since:
    Jan 2011

    Posted 28 Jun 2012 Link to this post

    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,

  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Jun 2012 Link to this post

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

  10. Alan
    Alan avatar
    32 posts
    Member since:
    Jan 2011

    Posted 29 Jun 2012 Link to this post

    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  

  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Jun 2012 Link to this post

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

  12. Alan
    Alan avatar
    32 posts
    Member since:
    Jan 2011

    Posted 29 Jun 2012 Link to this post

    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?
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Jun 2012 Link to this post

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

Back to Top
DevCraft banner