Posted 19 Dec 2012
Link to this post
I was having a problem, and was going to post asking for help, but I figured it out. And then thought I might post about the problem I ran into, and the solution, in case someone else runs into it.
I have a user control that contains a RadDataForm and a RadGridView, both of which have their ItemsSource properties bound to a QueryableCollectionView that is wrapped around an ObservableItemCollection.
And I have a "New" button that is bound to a command that calls RadDataForm.AddNewItem().
The objects in the collection were instances of a ORM record class, and the fields in the form and the the grid were bound to properties of the record class, and all was well and good.
Until I decided that I needed to add additional validation. I couldn't modify the record class - it is shared across several projects - so I did what I have often done, I defined a new wrapper class. The constructor for the new wrapper class took a an instance of the record class as an argument, and exposed it as a property (and also exposed the additional functionality I needed.)
So I modified the collection to contain instances of this wrapper class, and modified the bindings to properties of the record class property of the wrapper, instead of to properties of the record class itself. And then ran the program to see how it would do.
The grid displayed fine, and the form viewed existing records fine. But when I clicked my "New" button, AddNewItem() returned false.
This confused me. I could see how this would happen, if ItemsSource was bound to a fixed-size array, but I should be able to insert new items into a ObservableItemCollection.
The problem turned out to be the constructor of the wrapper class. It seems the element type in the collection must have a zero-argument constructor. Once I added this, everything worked again.
Posted 20 Dec 2012
Link to this post
Thank you for sharing your experience with the community.
the Telerik team