RadDataGrid for Windows 8 XAML enhancements Inline editing and data validation

Posted by: the telerik blogs, on 30 Jul 2013 | View original | Bookmarked: 0 time(s)


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


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



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)         {             this.SubmitChanges();           }           private async void SubmitChanges()         {             MessageDialog md = new MessageDialog("Changes were saved successfully.", "Data Saved.");             bool? result = null;             md.Commands.Add(                new UICommand("OK", new UICommandInvokedHandler((cmd) => result = true)));               await md.ShowAsync();         }     }

<telerikGrid:RadDataGrid.Commands>       <telerikGridCommands:DataGridUserCommand Command="{Binding CommitEditCommand, Source={StaticResource Model}}" Id="CommitEdit"  EnableDefaultCommand="True"/> </telerikGrid:RadDataGrid.Commands>

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

Download Source

Category: DataGrid | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1413 | Hits: 13

Similar Posts

  • Silverlight Release History : Q2 2009 (version 2009.2.701) more
  • Better XAML By Farr: WPF Line of Business Seminar more
  • Convert Web.UI Grid into a data entry spreadsheet more
  • Running the Same Query Against Multiple Databases more
  • LINQ To SQL more
  • How to simulate RowTest with MS Test more
  • Foundations of Programming - pt 2 Domain Domain Domain more
  • Forget about extending WPF data binding support more
  • Converting a LINQ to Entities query to a DataTable more
  • DataSet.WriteXmlSchema and DataSet.ReadXmlSchema Issue more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD