I am coming from the WPF Toolkit Datagrid. Everything I have done in WPF is using ObservableCollections. So I was surprised your grid didn't support them if you need to AddNew. So I created a new object that interits from ObservableCollection and Impliments IBindingList to suppor the AddNew.
What I am having a hard time figure out is how are CRUD operations supposed to be handled? Events on the Grid? Events on the underlining data collection? It seems I cannot find the best way to impliment those functions?
Also, another question. All my data is coming from LINQ queries, which I then cast to my special observable collection. But is there a way, out of the box, to use LINQ directly with the Datagrid so I dont have to cast to something else yet still have change tracking?
I hope in the future you do support ObservableCollections. As an experience WPF developer, that is pretty much all I use for Data Collections.
Hello,
Yes, the AddNewRecord in the XamDataGrid is exposed through the IBindingList interface. However, there are plenty of ways to go around this.
You can create a wrapper around your source, which implements IBindingList or IEditableCollectionView and not actually create your custom ObservableCollection.
Moreover, you can directly wrap your source (which is an observable collection) in a ListCollectionView or BindingList, like this:
xamDataGrid1.DataSource = new ListCollectionView(source);
xamDataGrid1.DataSource = new BindingList<Car>(source);
As far as the CRUD operations, they are all supported. Are you saying that if you delete a record from the XamDataGrid, the object is not deleted from the underlying data source?
Thanks for the quick reply.
Again, it may just be all on me because I am used to handling all the Add/Edit/Update/Delete in the Observable Collection. So it seems with your grid the way to do that is to handle these events in the Grid events of Added, Deleted, Updated. Is this correct? So my question is what is the recommended way to handle CRUD, in the grid events or in the underling data collection events?
Also, I am having to manually add a record to the grid. Would I add this to the underlining datasource or the grid itself? This is a bound grid.
The XamDataGrid will do all of this automatically.
If you need to handle CRUD operations, then yes, you can hook up to the RecordAdding/ed, RecordDeleting/ed, RecordUpdating/ed events. The -ing events are cancelable and you can cancel them if needed by setting the e.Cancel = true;.
If you are adding items in procedural code, then you should do it in the underlying data source and the XamDataGrid will automatically pick up the changes and create data records for the newly added objects.