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

Cancel Edit when selection changed

4 Answers 646 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vivien
Top achievements
Rank 1
Vivien asked on 16 Aug 2016, 03:17 PM

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

4 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 17 Aug 2016, 11:06 AM
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.
0
Vivien
Top achievements
Rank 1
answered on 17 Aug 2016, 04:14 PM

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

0
Vivien
Top achievements
Rank 1
answered on 17 Aug 2016, 04:18 PM

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?

 

0
Stefan Nenchev
Telerik team
answered on 18 Aug 2016, 12:33 PM
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.
Tags
GridView
Asked by
Vivien
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Vivien
Top achievements
Rank 1
Share this question
or