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

Cancel editing item

2 Answers 11 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 16 May 2014, 10:56 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 19 May 2014, 01:30 PM
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.
 
0
Stephan
Top achievements
Rank 1
answered on 19 May 2014, 03:34 PM
Hi Martin,

thanks that works great!

Tags
TreeView
Asked by
Stephan
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Stephan
Top achievements
Rank 1
Share this question
or