TreeviewItem Databinding

2 posts, 0 answers
  1. Robin Verhulst
    Robin Verhulst avatar
    6 posts
    Member since:
    Apr 2010

    Posted 20 Apr 2010 Link to this post

    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
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 22 Apr 2010 Link to this post

    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.
Back to Top