Load RadTreeViewItem

2 posts, 0 answers
  1. jean michel
    jean michel avatar
    36 posts
    Member since:
    Aug 2012

    Posted 21 May 2010 Link to this post

    Hello,

    I need to cover nodes of my treeview. Nodes is objects of the DtoHierarquiaAgrupamento class.
     
    It follows the code below:
     foreach (Telerik.Windows.Controls.RadTreeViewItem item in RadHierarquia.Items)  
                    {  
     
                        //codeblock  
                    } 
     
    Error:

    Unable to cast object of type 'CCM7.DTO.DtoHierarquiaAgrupamento' to type 'Telerik.Windows.Controls.RadTreeViewItem'.

    Thanks..!
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 21 May 2010 Link to this post

    Hi jean michel,

    RadHierarquia.Items collection contains items of type DtoHierarquiaAgrupamento. Therefore you need to modify the foreach like so:
    foreach (DtoHierarquiaAgrupamento item in RadHierarquia.Items) 
       
     
            //codeblock 
       }
    or you can do it like so:
    foreach (var item in RadHierarquia.Items) 
        
      
             //codeblock 
        }

    However, if you need to use the RadTreeViewItem containing the item, you can use the ContainerFromItemRecursive method of the RadTreeView:
    RadTreeViewItem treeItem = myRadTreeView.ContainerFromItemRecursive(item);

    Give this a try and let me know if it works for you.

    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