Add-New-Record for any type of collection bound to the XamDataGrid

John Doe / Monday, November 23, 2009

Currently, the XamDataGrid supports the AddNewRecord functionality for only collections which implement the IBindingList interface( like BindingList<T> and DataView). With couple of easy tricks and few lines of code, you can achieve a similar functionality for any collection:

1. Distinguish between a normal record and the add record - use the Tag property.

2. Fix the Add New Record so that it looks like the real one - use IsFixed property.

3. Commit the Add New Record - DataPresenterCommands.CommitChangesToActiveRecord.

4. Restyle the Add New Record - Styles for the DataRecordCellArea & RecordSelector.


You can find a full sample in the attachments of this blog post.

Known possible drawbacks :

1. One extra blank record is present in the data source at all times ( as the built-in functionality creates this record once you have started data input in the add record).

2. The implementation for hierarchical data structure is left out for your exercise.