How to remove nodes only from tree but not from DataSource

6 posts, 0 answers
  1. Balaram Barange
    Balaram Barange avatar
    28 posts
    Member since:
    Apr 2009

    Posted 24 Jul 2009 Link to this post

    Hi,

    We are using OnDemandLoad and binded tree with our datastructure. Howevere in certain case say if A is true then we do not want a certain node say Node1 to expand eventhough it gets data on demand i.e. only parent Node1 should be shown but no Childrens of it but at the same time we do not want to remove it from out binded datasource - in essence we need to hide them from tree.

    Hope you get the problem. Please provide us ways/code lines to achieve this.

    Thanks in advance,
    Balaram
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 24 Jul 2009 Link to this post

    Hi Balaram Barange,

    I have two suggestions:
    1. If you want to hide only some of the children - then you will be able to set their visibility. You can also bind the visibility of the item container using ContainerBindings (similar to WPF's Style Bindings, but added as an attached collection to the DataTemplate).

    Do you need more help with the container bindings?

    2. If you want to hide all the children, collapsing them will not work since the expand button will still be visible. If you want to hide them, it is best to change the collection property (i.e. not the collection itself) of their parent. Just make sure that the items source that has generated the items is an observable property. (The property that you bind to in the hierarchical data template). Then, when you want to hide the items , raise the OnChanged event and make sure the property returns an empty Enumerable (Empty collection) from then on. Since you may be using the property yourself, better create another property that will change when you need it and keep the actual collection property always returning what you expect it to.

    Hopefully this will work for you,

    All the best,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Balaram Barange
    Balaram Barange avatar
    28 posts
    Member since:
    Apr 2009

    Posted 24 Jul 2009 Link to this post

    Hi Miroslav,

    Thanks for your prompt reply.

    It will be really great if you provide some sample code to implement your 2nd suggestion using Binded Obsevable collection approach.
    As we need to hide all the children of a node even if the data for the node is available in the data source.

    Thanks in advance,
    Balaram
  4. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 24 Jul 2009 Link to this post

    Hi Balaram,

    I am sorry that I mistakenly created the example in Silverlight. Since the controls are the same, you should be able to reuse the code though.

    The example also shows how you can use a TemplateSelector, but you probably know this already.

    The trick with returning the empty collection is in the OrganisationModel class.

    Please find the example attached.

    Kind regards,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Balaram Barange
    Balaram Barange avatar
    28 posts
    Member since:
    Apr 2009

    Posted 04 Aug 2009 Link to this post

    Hi Miroslav,

    Thanks for sharing the sample.

    But we are not able to figure out the exact code lines to hide the children of a node as when we run the sample code the application window appears in which we are not finding any node whose children are there in datasource and not being displayed in the window.

    are there any settings we need to switch on?

    Thanks in advance
    Balaram
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Aug 2009 Link to this post

    Hello Balaram,

    I must admit that I have made a mistake and I attached a project that was meant for a different reply.
     
    Now, the correct example is attached. I also created it in WPF as well.

    You can look at the OrganisationModel class which has an AreChildrenVisible property. The trick is that the setter of this property raises the PropertyChanged event not just for it but for the Children collection as well. Then the getter of the collection property of the returns a different collection depending on the value of the AreChildrenVisible property. Normally you should not return a different value for a property in this strange manner but this property is not meant to be used in code but rather to "lie" to the TreeView in this specific case.

    Again, please excuse me for attaching the wrong project in the last reply.

    Kind regards,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top