WPF MVVM Light DataForm

4 posts, 0 answers
  1. Alberto
    Alberto avatar
    3 posts
    Member since:
    Sep 2013

    Posted 21 Jan 2014 Link to this post

    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!

  2. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 24 Jan 2014 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alberto
    Alberto avatar
    3 posts
    Member since:
    Sep 2013

    Posted 28 Jan 2014 in reply to Yoan Link to this post

    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();
                    }
                }
            }
  5. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 31 Jan 2014 Link to this post

    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 >>
Back to Top