Since Q2 we have introduced new vital feature for our RadDataGrid – editing. It includes build-in strongly typed editors as well as data validation support. So, using the component for editing scenarios is as simple as possible. Just set UserEditMode and provide the appropriate ItemsSource and you are done.

               DataContext="{StaticResource Model}"
               ItemsSource="{Binding Data}”


Of course when we talk about editing, we need some mechanism to validate our data. With our DataGrid we have provided easy to use API through the INotifyDataErrorInfo interface and our ValidateViewModelBase class that implements it. So, if a certain property needs certain validation rules it can do with a few lines of code:

public class TaskData : ValidateViewModelBase
     public DateTime? StartDate
            get { return startDate; }
                startDate = value;
                if (startDate > endDate)
                    this.AddError("StartDate", "Start Date cannot be set after the end date.");

Doing that will provide RadDataGrid with enough information to trigger validation during editing.



The other interesting face of the editing is the flexible MVVM friendly API. RadDataGrid exposes several commands that cover the whole edit operation:

  • BeginEdit command
  • CommitEdit command
  • CancelEdit command
  • ValidateCell command

We leveraged the current command infrastructure available in RadDataGrid from the previous versions. Here is an example how to utilize CommitEditCommand:

public class CustomCommitEditCommand : ICommand
        public bool CanExecute(object parameter)
            return true;
        public event EventHandler CanExecuteChanged;
        public void Execute(object parameter)
        private async void SubmitChanges()
            MessageDialog md = new MessageDialog("Changes were saved successfully.", "Data Saved.");
            bool? result = null;
               new UICommand("OK", new UICommandInvokedHandler((cmd) => result = true)));
            await md.ShowAsync();

Command="{Binding CommitEditCommand, Source={StaticResource Model}}"

All these and more are available for download in our RadControls for Windows 8 suite.

Download Source

About the Author

Tsvyatko Konov

Tsvyatko Konov is the Lead of UI for Xamarin and UI for UWP team. He is keen on sharing technical experience through mentoring and team development as well as in publications and lectures. In his spare time, TK loves sailing and skiing.

Related Posts


Comments are disabled in preview mode.