TreeView Master/Details Scenario example

5 posts, 1 answers
  1. Alexey Oyun
    Alexey Oyun avatar
    74 posts
    Member since:
    Mar 2010

    Posted 23 Jun 2010 Link to this post

      Hi, could you post an example of Master/Details Scenario with treeview through DataContext binding.

      For simplicity we will have treeview with persons. Next to it two text boxes with name and surname in stackpanel that has bindning to selected item. And button save changes.
      I need to save person data and reflect it in treeview. 
      I am using ObservableCollection for items, but changes to the item do not reflect in treeview.
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 25 Jun 2010 Link to this post

    Hello Alexey Oyun,

    I prepared a sample project illustrating hot to implement the described scenario. Please note that the Client data class that implements INotifyProperyChanged thus applying the changes made to the names through the textBoxes thus changing the data collection of the RadTreeView. Also, keep in mind that the changes will be reflected in the business object only if the TextBox's Text property is data bound in a TwoWay binding mode.

    Take a look at the project and let me know if this is what you had in mind.

    Regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Alexey Oyun
    Alexey Oyun avatar
    74 posts
    Member since:
    Mar 2010

    Posted 28 Jun 2010 Link to this post

      Yes this is pretty much what I wanted.
      One question, how did you trigger save. In code I could not find any reference (Event or Command bindning) to Save button.
      Or is it default action for the button that in control bound to ObservableCollection item?
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 28 Jun 2010 Link to this post

    Hello Alexey Oyun,

    Actually in the example, I haven't implemented any logic behind the Save button, since I wasn't sure if you have specific requirements for it.

    However, since the TextBoxes are bound in a TwoWay mode and the Client class implements INotifyPropertyChanged, any changes made to the Name and LastName through the TextBoxes, are reflected on the original data source, which in this case is the Clients observable collection. And since the ObservableCollection implements INotifyCollectionChanged, any changes in it are applied to the ItemsSource collection of the tree.

    Therefore if this logic satisfies the requirements of your scenario, a Save button won't be neccessary. Still, if the Clients collection needs to be further saved, you can implement custom logic using a Save button.

    I hope this information will help you. Also, if you need more, please let us know.

    Best wishes,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Alexey Oyun
    Alexey Oyun avatar
    74 posts
    Member since:
    Mar 2010

    Posted 29 Jun 2010 Link to this post

    Thank you Tina, I just figured out.
    If I change last name and than select name textbox changes propagate to treeview through bindning.
    But if I change lastname and than click to another node, changes won't propagate to treeview.
    So if I want to change only last name I should click somewhere it the form to apply changes. Otherwise they are going to be lost. Or subscribe to textchanged event.

    Well this is another story, so lets close this thread.

    Once again, thanks Tina.

    Sincerely, Alexey


Back to Top