This question is locked. New answers and comments are not allowed.
Hello Telerik Team !
I have a RadGridView like that :
And his code behind here :
Finaly my model is :
Now my problem is :
When the user cancel his modifications only the modifications on "Ri1Simu"'s property are cancelled and "Ri1Cond", "Ri1Prev" properties are not :(
How can i achieve this ?
Thanks for your help guys !
Joachim.
I have a RadGridView like that :
<telerikGridView:RadGridView x:Name="radGridViewSimulations" Grid.Row="1" EditTriggers="None" IsReadOnly="False" ActionOnLostFocus="None" AutoGenerateColumns="False" CanUserReorderColumns="False" DataLoaded="radGridViewSimulations_DataLoaded" BeginningEdit="radGridViewSimulations_BeginningEdit" RowEditEnded="radGridViewSimulations_RowEditEnded"> <telerikGridView:RadGridView.Columns> <telerikGridView:GridViewDataColumn Header="Ri1" IsReadOnly="False" IsGroupable="False" DataMemberBinding="{Binding Ri1Simu}" > <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Border Grid.Column="0" Grid.Row="2"> <TextBlock Text="{Binding Ri1Simu}" TextAlignment="Center" /> </Border> <Border Grid.Column="0" Grid.Row="3" > <TextBlock Text="{Binding Ri1Cond}" TextAlignment="Center" /> </Border> <Border Grid.Column="0" Grid.Row="4" > <TextBlock Text="{Binding Ri1Prev}" TextAlignment="Center" /> </Border> </Grid> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> <telerikGridView:GridViewDataColumn.CellEditTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Grid.Row="2" Text="{Binding Ri1Simu, Mode=TwoWay}" /> <TextBox Grid.Column="0" Grid.Row="3" Text="{Binding Ri1Cond, Mode=TwoWay}" /> <TextBox Grid.Column="0" Grid.Row="4" Text="{Binding Ri1Prev, Mode=TwoWay}" /> </Grid> </DataTemplate> </telerikGridView:GridViewDataColumn.CellEditTemplate> </telerikGridView:GridViewDataColumn> <telerikGridView:GridViewDataColumn IsReadOnly="True" IsGroupable="False" Header="Actions"> <telerikGridView:GridViewDataColumn.CellTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <telerik:RadButton Grid.Row="1" Grid.Column="0" Click="btnEdit_Click" x:Name="btnEdit" Content="Modifier" /> <telerik:RadButton Grid.Row="1" Grid.Column="0" Click="btnCancel_Click" x:Name="btnCancel" Content="Annuler" Visibility="Collapsed" /> <telerik:RadButton Grid.Row="2" Grid.Column="0" Click="btnSave_Click" x:Name="btnSave" Content="Enregistrer" Visibility="Collapsed" /> </Grid> </DataTemplate> </telerikGridView:GridViewDataColumn.CellTemplate> </telerikGridView:GridViewDataColumn> </telerikGridView:RadGridView.Columns></telerikGridView:RadGridView>And his code behind here :
public partial class SimulationsCustomersPage : Page { /// <summary> /// Flag set to true when the page is initialized /// </summary> private bool _isInitialized = false; /// <summary> /// Data model of this page /// </summary> private SimulationCustomerListViewModel _model; /// <summary> /// The current grid's row which can be in edit mode /// </summary> private GridViewRow _currentRow; /// <summary> /// Flag set to true when a gridview's row is in edit mode /// </summary> private bool _hasRowInEditMode = false; /// <summary> /// The current edit button /// </summary> private RadButton _currentEditButton; /// <summary> /// The current cancel button /// </summary> private RadButton _currentCancelButton; /// <summary> /// The current save button /// </summary> private RadButton _currentSaveButton; /// <summary> /// Flag set to true when the user click on save button /// </summary> private bool _isValid; public SimulationsCustomersPage() { InitializeComponent(); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (!_isInitialized) { radGridViewSimulations.IsBusy = true; _model = new SimulationCustomerListViewModel(); Binding binding = new Binding("Simulations"); binding.Source = _model; radGridViewSimulations.SetBinding(RadGridView.ItemsSourceProperty, binding); _isInitialized = true; } } private void radGridViewSimulations_DataLoaded(object sender, EventArgs e) { radGridViewSimulations.IsBusy = false; } private void btnEdit_Click(object sender, RoutedEventArgs e) { if (!_hasRowInEditMode) { _hasRowInEditMode = true; //Hide and show adequate buttons _currentEditButton = ((RadButton)sender); _currentCancelButton = ((RadButton)sender).ParentOfType<Grid>().FindName("btnCancel") as RadButton; _currentSaveButton = ((RadButton)sender).ParentOfType<Grid>().FindName("btnSave") as RadButton; //Sets the 'Ri1' cell in edit mode _currentRow = (sender as UIElement).ParentOfType<GridViewRow>(); radGridViewSimulations.CurrentItem = _currentRow.Item; var cell = _currentRow.GetCellFromPropertyName("Ri1Simu"); cell.IsCurrent = true; radGridViewSimulations.BeginEdit(); } else { RadWindow.Alert(new DialogParameters() { Content = "Vous ne pouvez modifier qu'une ligne à la fois.\nVeuillez annuler ou valider vos modifications courantes pour continuer", Header = "Action non autorisée" }); } } private void btnCancel_Click(object sender, RoutedEventArgs e) { radGridViewSimulations.CancelEdit(); } /// <summary> /// Show save/cancel buttons and hide edit button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void radGridViewSimulations_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e) { if (_hasRowInEditMode) { //We authorize temporarly to use a click on a cell to enter in edit mode radGridViewSimulations.EditTriggers = GridViewEditTriggers.CellClick; _currentEditButton.Visibility = System.Windows.Visibility.Collapsed; _currentCancelButton.Visibility = _currentSaveButton.Visibility = System.Windows.Visibility.Visible; } } /// <summary> /// Save the user's modification and exit the edit mode /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, RoutedEventArgs e) { //the grid is valid now ! _isValid = true; radGridViewSimulations.CommitRowEdit(_currentRow); } private void radGridViewSimulations_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e) { _hasRowInEditMode = false; _isValid = false; _currentSaveButton.Visibility = _currentCancelButton.Visibility = System.Windows.Visibility.Collapsed; _currentEditButton.Visibility = System.Windows.Visibility.Visible; //The use of a click to enter in edit mode is forbidden radGridViewSimulations.EditTriggers = GridViewEditTriggers.None; if (e.EditOperationType == GridViewEditOperationType.Edit) { //Update the data base ! } } }Finaly my model is :
public partial class Simulation : INotifyPropertyChanged{ #region INotifyPropertieChanged Members public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } } #endregion public virtual decimal Ri1Simu { get { return _ri1Simu; } set { if (_ri1Simu != value) { _ri1Simu = value; OnPropertyChanged("Ri1Simu"); } } } private decimal _ri1Simu; public virtual decimal Ri1Cond { get { return _ri1Cond; } set { if (_ri1Cond != value) { _ri1Cond = value; OnPropertyChanged("Ri1Cond"); } } } private decimal _ri1Cond; public virtual decimal Ri1Prev { get { return _ri1Prev; } set { if (_ri1Prev != value) { _ri1Prev = value; OnPropertyChanged("Ri1Prev"); } } } private decimal _ri1Prev;}Now my problem is :
When the user cancel his modifications only the modifications on "Ri1Simu"'s property are cancelled and "Ri1Cond", "Ri1Prev" properties are not :(
How can i achieve this ?
Thanks for your help guys !
Joachim.