I have tried creating Templates (with AutoGenerateFields="False") but it did not make a difference.
6 Answers, 1 is accepted
The functionality for inserting new items and discarding the changes depends entirely on the type of the data source. What is the collection you bind your data form to ?
You can also run through our online documentation for a reference on how to bind the data form.
Maya
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Also, going thru the docs, I did not find a "section" that talks about how different data sources will behave. Can you please help out?
Generally, the behavior of the data form according to the different types of data source would be the same as to all the other controls. For example if a collection does not support insertion of new items, you will not be able to add one neither with RadDataForm, nor with RadGridView or RadTreeListView for example.
I am sending you a sample project illustrating how you may insert a new item when the RadDataForm is bound to an ObservableCollection. If you want to support reverting of the changes made, you need to implement IEditableObject Interfaced as mentioned in the documentation.
Let me know in case you need any additional assistance.
Maya
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
I found my problem and the way I see it, it has nothing to do with the type of the data source. When I hear/read "type of the data source" I immediately think of a Data Type, like List, ObservableCollection, Dictionary etc. The problem was the way I had defined the base class, which had one constructor that expected all the fields to be passed in (as opposed to an empty constructor)
Bad constructor
public Task(string name, string description)
{
this.Name = name;
this.Description = description;
}
Good constructor
public Task()
{
}
In fact, the collection type can be of List type or ObservableCollection type and it works fine either way, the Add function that is. So the problem was the Constructor in the base class, not the collection nor the collection data type. Now that I think about this it makes sense but this did not click yesterday while looking at this problem. What I need to look into now is implementing the IEditableObject interface to allow the "cancel" operation.
I am going to post my code sample once I have it worknig.
Indeed, if no default constructor is available, insertion of an item will not be possible. I should have mentioned it before. Still, I am really happy to see that you found the cause of the problem. Please let me know in case you need any further assistance.
Maya
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>