Cancel Edit when selection changed

5 posts, 0 answers
  1. Vivien
    Vivien avatar
    6 posts
    Member since:
    Apr 2016

    Posted 16 Aug Link to this post

    Hello,

    I'm now developing a table to edit a List. I have only one problem, i wan't to cancel edit when user change row without saving with a button on the left of the row.

    I use RadGridView and i have try this: ActionOnLostFocus="CancelEdit" but it don't work...

    <telerik:RadGridView x:Name="MyGrid" MaxHeight="500"
         CellEditEnded="GridConfig_OnCellEditEnded"
         BeginningEdit="EditGrid_BeginningEdit"
        RowLoaded="EditGrid_RowLoaded"
        CanUserFreezeColumns="True"
        EnableColumnVirtualization="False"                                    
        AutoGenerateColumns="False"
         RowEditEnded="GridConfig_OnRowEditEnded"
        ItemsSource= "{Binding ConfigurationList, Mode=OneWay,
         UpdateSourceTrigger=PropertyChanged}">

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 17 Aug Link to this post

    Hello Vivien,

    The ActionOnLostFocus concerns the action taken when the RadGridView loses focus. In a case of changing the rows, the focus stays within RadGridView.

    With this in mind, you can consider utilizing the PreviewMouseLeftButtonDown event and invoke RadGridView`s CancelEdit command in case a user clicks outside of the selected row:

    private void clubsGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
           {
               if (clubsGrid.RowInEditMode != null && (e.OriginalSource as FrameworkElement).ParentOfType<GridViewRow>() != clubsGrid.CurrentCell.ParentRow)
               {
                   (sender as RadGridView).CancelEdit();
               }
           }

    Please check the sample provided.

    Another possibility is to explicitly declare the element within each Column, set the UpdateSourceTrigger Property of the binding to Explicit and call the UpdateSource() method in the scenarios you want(press Tab, press Enter, etc).

    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vivien
    Vivien avatar
    6 posts
    Member since:
    Apr 2016

    Posted 17 Aug in reply to Stefan Nenchev Link to this post

    Thank you for the answer, it's york well.

    Now i have a new problem because, when i modify two or more cell in the row, and i throw CancelEdit, the only last cell go back to last value, all other stay with modifications...

  5. Vivien
    Vivien avatar
    6 posts
    Member since:
    Apr 2016

    Posted 17 Aug in reply to Stefan Nenchev Link to this post

    Thank you for the answer, it's work well, but now i have a new problem...

    When i modify 2 or more cell and throw CancelEdit, the only last cell come back to last value, the other stay with updates... Have you got an idea for Cancel all updates?

     

  6. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 18 Aug Link to this post

    Hi Vivien,

    I tried to come up with a workaround for you but actually in the sample project provided the default behavior is the one you seek for. Please review the following video I have recorded - http://screencast.com/t/ZbqTLYRx. Am I missing something or is the behavior in your application different? Can you raise a ticket with a sample project which we can investigate?

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready