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

TreeviewItem Databinding

1 Answer 53 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robin Verhulst
Top achievements
Rank 1
Robin Verhulst asked on 20 Apr 2010, 09:59 AM
I fill my treeview with objects (SimpleAssetData objects) but after i added the asset to the treeview i want to set the defaultimagesrc to  asset.assetType + ".png";   How do i do this
RadTreeViewItem parentTree = tvAssetOverview.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem; 
            SimpleAssetData asset2 = parentTree.Item as SimpleAssetData; 
            parentTree.DefaultImageSrc = "Images/" + asset2.AssetType.ToString() + ".png"; 
            foreach (SimpleAssetData asset in e2.Result) 
            { 
                parentTree.Items.Add(asset); 
                parentTree.ItemContainerGenerator.ContainerFromItem(asset); 
            } 
            tvAssetOverview.ExpandAll(); 
 
            Collection<RadTreeViewItem> allTreeContainers = GetAllItemContainers(parentTree); 
            foreach (RadTreeViewItem item in allTreeContainers) 
            { 
                SimpleAssetData asset3 = item.Item as SimpleAssetData; 
                item.DefaultImageSrc = "Images/" + asset2.AssetType.ToString() + ".png"; 
            } 
doesn't work

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 22 Apr 2010, 05:36 PM
Hello Robin Verhulst,

I noticed that your collection has a number of levels, therefore I'd suggest you use the GetItemByPath() method of the RadTreeView to get the radTreeViewItems and then you can set the DefaultImageSrc like you do.

I prepared a sample project demonstrating this approach. Please take a look at it and let me know if it helps. Also keep in mind that in order to use the GetItemByPath() method you will have to override the ToString() method of the business class.

Greetings,
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.
Tags
TreeView
Asked by
Robin Verhulst
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or