Cancel editing item

3 posts, 1 answers
  1. Stephan
    Stephan avatar
    14 posts
    Member since:
    Nov 2013

    Posted 16 May 2014 Link to this post

    Hi there,
    I've got a little problem with my application.
    I get my data from a database and it is shown in a RadTreeView. When I edit an item a new RadWindow appears with all the data of the item inside, like Serialnumber, manufacturer...

    I've implemented two buttons for saving and canceling the action.
    Saving writes the data into my database and refreshes the TreeView.
    It is not very nice looking, because the hole RadTreeView will be unloaded and loaded again, so i get my database key item_ID to save it again if new changes will be made.
    Maybe you have a better way to do this.

    But the big problem is my cancelation.
    If the EditPage is loaded a create a new object with the DataContext of the selected item, for backup issues.
    If i cancel editting i do following:

    private void EditPage_Cancel(object sender, RoutedEventArgs e)
            {
                this.DataContext = editBackup;
                this.Close();
            }

    So my database isn't involved but the RadTreeViewItem has the values before the canceling.
    What is my mistake in this case?

    Regards
    Stephan

  2. Answer
    Martin
    Admin
    Martin avatar
    1099 posts

    Posted 19 May 2014 Link to this post

    Hello Stephan,

    I cannot be sure until I see your implementation, but my guess is that the DataContext of your EditPage is not connected with the tree view item that you are editing in your main page. However, I can suggest you an approach similar to your implementation. You can create a DataItem which holds the original view model from the tree. Then create a deep copy of this item and pass it as a DataContext of the EditPage. When you click the Save button you can set the properties of the original view model to the values in the deep copy that is edited. On Close button click just close the page.

    For your convenience I prepared a sample project demonstrating this approach. 

    Regards,
    Martin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Stephan
    Stephan avatar
    14 posts
    Member since:
    Nov 2013

    Posted 19 May 2014 Link to this post

    Hi Martin,

    thanks that works great!

Back to Top