This is a migrated thread and some comments may be shown as answers.

WPF MVVM Light DataForm

3 Answers 195 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Alberto
Top achievements
Rank 1
Alberto asked on 21 Jan 2014, 03:03 PM

Hi,
I'm looking for an example of using RadDataForm to Update and/or Insert data in a SQL Server table in a WPF MVVM Light application.

I've binding DataForm with a LIST that contains a result of a sql query but I've not idea how to update or inser a value.

Thank's a lot!

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 24 Jan 2014, 03:14 PM
Hello Alberto,

Generally, you can try to extend the default DataForm Commands. For example, you can save the changes in your database after the CommitEdit command is executed. Here is a nice example, which shows you how to customize DataForm's commands in a MVVM-friendly way. The same example is available in local copy of WPF demos. You can check this help article as well.

I hope this helps.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Alberto
Top achievements
Rank 1
answered on 28 Jan 2014, 11:18 AM
Ok but why the command CancelEdit() od CommitEdit() don't commit? The message is showed but the item remains the same in DB

This is the code:
        protected override void CommitEdit() {
            MessageBoxResult result = MessageBox.Show("Commit changes for the current edit item?", "CommitEdit confirmation", MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK) {
                if (this.DataForm != null && this.DataForm.ValidateItem()) {
                    this.DataForm.CommitEdit();
                }
            }
        }
0
Yoan
Telerik team
answered on 31 Jan 2014, 12:05 PM
Hi Alberto,

I am sorry if I was not clear enough. If what you want is to save your changes to the database, then you need to call dataContex.SubmitChanges(). It will be something similar to this:
protected override void CommitEdit() {
       MessageBoxResult result = MessageBox.Show("Commit changes for the current edit item?", "CommitEdit confirmation", MessageBoxButton.OKCancel);
       if (result == MessageBoxResult.OK) {
           if (this.DataForm != null && this.DataForm.ValidateItem()) {
               this.DataForm.CommitEdit();
 
               dataContex.SubmitChanges();
           }
       }
   }
In this way, every item that was changed at RadDataForm will be saved to the database.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DataForm
Asked by
Alberto
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Alberto
Top achievements
Rank 1
Share this question
or