The DomainDataSource is bound to a collection of Customers
I load the dataform and using "Editor.AddNewItem()", the editor will show the AddNew template... fine
I have added a "Save" button to the dataform by overriding the base controltemplate. When the user clicks the "Save" button, an MVVM command will call SubmitChanges on the DomainDataSource.
I have hooked up the ChangesSubmitted event of domaindatasource... it will now load the customer that was just added:
This works fine... the dataform will show the added record, but the editor continues to use the AddNew template... how can i switch to the edit template?
6 Answers, 1 is accepted
Could you try to invoke CommitEdit command of RadDataForm as well? Do you get the same behavior ?
the Telerik team
Does not change anything, the AddNew template remains the active template
I have tried to reproduce the issue you reported, but still without any success. Could you share a bit more information about your exact scenario ? Generally, any relevant information and code-snippet would be helpful so that I could simulate your scenario.
the Telerik team
I would be very interested in seeing that sample wherein this works if you have one.
The scenario i'm using is quite complicated and it has a lot of code. It also uses MVVM.
I did the following:
I have create a custom dataform component "ExqiDataForm" that inherits from RadDataForm. The reason why i did that is so that i could override the control template for all of the RadDataForms of that type. In the control template i added a third button "Save".
I have created a RadWindow for editing the details of an Entity called "OrganizationUser". On that window i have placed a ExqiDataForm with two templates... one for Adding and one for Editing an OrganizationUser. The dataform is bound to a DomainDataSource.
When the user clicks on the Add button in the main application, it will instantiate the RadWindow containing the ExqiDataForm and it will execute following code on the ExqiDataForm:
This will effectievely make the OrganizationUserEditor display the AddNew template.
When the user clicks on the SAVE button on the ExqiDataForm, it will execute an MVVM command that will execute a SubmitChanges() on the RadDomainDataSource. I have also hooked the SubmittedChanges event on the DomainDataSource bound to the dataform. So when SubmitChanges is executed in MVVM, the SubmittedChanges event is fired right after. In this event, i reload the DomainDataSource like this:
This is necessary, otherwise the DomainDataSource will not contain the database record that we will edit straight after. It is here that it goes wrong... i would expect the DataForm to be in edit mode right after this load() command, but it is not.
What am i doing wrong?
I am attaching the sample project I used for the test. As I am not aware of your custom command, I just handled Click event of the Save button and called the CommitEdit() and SubmitChanges() methods. Still. once the Save button is pressed, the new item is saved and the template for a new item is change with a one for read-only mode.
Could you take a look at the application and let me know whether you can get the same behavior on it as the one in your project ? Is there anything that I am missing ?
the Telerik team
Thanks for putting up the effort for creating a demo app.
My situation is quite different because i'm using DataTemplates to edit the data.
Because the command executed by the save button is in a viewmodel, it's not so easy to execute CommitEdit on the dataform object.
So I have leaked the DataForm to the viewmodel and executed the "CommitEdit" on it in the viewmodel. This has done the trick and the dataform now switches from AddNew template to the Edit template without problems.
It's not particularly "clean", but i don't see any other option right now and it does solve my problem.
Thanks a lot for you help!