Overview

Since Q2 we have introduced a 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.

<telerikGrid:RadDataGrid

DataContext="{StaticResource Model}"

ItemsSource="{Binding Data}”

UserEditMode="Inline"/>

Validation

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:

publicclassTaskData : ValidateViewModelBase

{

publicDateTime? StartDate

{

get{ returnstartDate; }

set

{

startDate = value;

if(startDate > endDate)

{

this.AddError("StartDate", "Start Date cannot be set after the end date.");

}

else

{

this.RemoveErrors("StartDate");

}

this.OnPropertyChanged();

}

}

}

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

Commands

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:

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.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.