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

Add items to node's Children collection when expanded

1 Answer 61 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Szymon
Top achievements
Rank 1
Szymon asked on 12 Feb 2015, 09:06 AM
Hello,
I'm useing RadTreeListView and have bound an ObservableCollection of TypeA to ItemsSource. 
<telerik:RadTreeListView.ChildTableDefinitions>
    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children }" />
</telerik:RadTreeListView.ChildTableDefinitions>

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

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 13 Feb 2015, 10:51 AM
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.

Regards,
Dimitrina
Telerik
 

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.

 
Tags
TreeListView
Asked by
Szymon
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or