Add items to node's Children collection when expanded

2 posts, 0 answers
  1. Szymon
    Szymon avatar
    1 posts
    Member since:
    Feb 2015

    Posted 12 Feb 2015 Link to this post

    I'm useing RadTreeListView and have bound an ObservableCollection of TypeA to ItemsSource. 
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children }" />

    When I add first item of TypeB (derived from TypeA) to collection, then expand node and try to add second item of TypeA to collection I get error "unable to cast object of type TypeA to type TypeB. 

    I know that when node is not expanded, it's item container doesn't exist and there is no problem adding object of different types (derived from same type) to collection. On the other hand when the node is expanded, it's item container doesn't store items of same type as bound collection but items of type which is actual in bound collection. In my example TypeB, so you can't add items of TypeA due to cast issue.

    Temporarily I just collapse node, add item, then expand node again. For me it isn't elegant solution, but maybe I'm wrong.

    Is it a know problem/bug for you? How should I deal with it properly? 

    Szymon Wesolowski
  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 13 Feb 2015 Link to this post

    Hi Szymon,

    Generally, I would suggest you using RadTreeListView for displaying homogeneous data only as your bound object should have a hierarchical Items collection defined with the same structure. You can check our online documentation on how RadTreeListView works and how to specify the hierarchy Item.

    As to your specific question, you can try specifying the correct RadTreeListView.Items.ItemType.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top