Getting a TreeviewItem and more !!

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

    Posted 28 Apr 2010 Link to this post

    Ive been having these problems for a long time and i'm starting to get desperate. I'm gonna try to explain the assignment so you can maybe give a good solution.

    I'm creating a silverlight app to display Assets into a GISMAP.To do this i load them into a Radtreeview.
    Now because i have to use Async webservices i can't use my recursive method anymore and i can only show 1 parent with his children ( PROBLEM 1)
    first i get the requested asset
     void OnGetAssetSimpleCompleted(object sender, GetAssetSimpleCompletedEventArgs e) 
            { 
                SimpleAssetData parent = e.Result; 
                tvAssetOverview.Items.Add(parent); 
                RadTreeViewItem parentTree = tvAssetOverview.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem; 
                // kinderen ophalen 
                 
                assetProxy.GetChildrenSimpleAsync(_assetID, _assetType); 
            } 

    this is my completed eventhandler in which i get the children from that parent

     void OnGetChildrenSimpleCompleted(object sender2, GetChildrenSimpleCompletedEventArgs e2) 
            { 
                if (currentItem == null) 
                { 
                    currentItem = tvAssetOverview.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem; 
                } 
                SimpleAssetData asset2 = currentItem.Item as SimpleAssetData; 
                currentItem.DefaultImageSrc = "Images/" + asset2.AssetType.ToString() + ".png"; 
                currentItem.IsLoadingOnDemand = false
                foreach (SimpleAssetData asset in e2.Result) 
                { 
                    currentItem.Items.Add(asset); 
                } 
     
                tvAssetOverview.ExpandAll(); 
     
                currentItem = null
                CheckItems(); 
            } 

    Then i want to load pictures for every asset in the treeview and enable loadondemand for every asset that has children ( i included a property HasChildren in the SimpleAssetData object to make it easier )  ( PROBLEM 2 )

    i tried alot

    RadTreeViewItem parentItem = tvAssetOverview.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem; 
                string path = ""
     
                foreach (SimpleAssetData item in parentItem.ItemsSource) 
                { 
                    path = parentItem.ToString() + "|" +  item.ToString(); 
                    RadTreeViewItem treeViewItem = tvAssetOverview.GetItemByPath(path); 
                    treeViewItem.DefaultImageSrc = "Images/" + item.AssetType.ToString() + ".png"; 
                } 
    does not work

       RadTreeViewItem parentItem = tvAssetOverview.ItemContainerGenerator.ContainerFromIndex(0) as RadTreeViewItem; 
                for (int i = 0; i < parentItem.Items.Count; i++) 
                { 
                    RadTreeViewItem childItem = parentItem.ItemContainerGenerator.ContainerFromIndex(i) as RadTreeViewItem; 
                    //SimpleAssetData assetData = childItem.Item as SimpleAssetData; 
                    //childItem.DefaultImageSrc = "Images/" + assetData.AssetType.ToString() + ".png"; 
                    if ((childItem.Item as SimpleAssetData).HasChildren == true) 
                    { 
                        childItem.IsLoadingOnDemand = true
                    } 
                } 
    doesn't work either

    Please Help
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 30 Apr 2010 Link to this post

    Hello Robin,

    I'm not sure that I fully understand what the )1 issue is. Could you please elaborate a little bit more on the subject.
    As for 2), why don't you use ContainerBindings to set the images. Give it a try and let me know how I can be of further assistance.

    Kind regards,
    Kiril Stanoev
    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.
  3. Robin Verhulst
    Robin Verhulst avatar
    6 posts
    Member since:
    Apr 2010

    Posted 30 Apr 2010 Link to this post

    1. How would i bind the defaultimagesrc of the Radtreeview item to 'Images/' + SimpleAssetData.AssetType + '.png'       SimpleAssetData being the object inside the treeviewitem

    2. The main issue is that i can't the the nodes under the parent node .
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 30 Apr 2010 Link to this post

    Hi Robin Verhulst,

    I noticed that you are using the ItemContainerGenerator to get the item containers. Please note that these containers will not be generated until needed (until visible), but you can handle the ItemContainerGenerator.StatusChanged event and be notified when they are generated.

    Example code for getting the containers:
    myTreeView.ItemContainerGenerator.StatusChanged += new EventHandler(ItemContainerGenerator_StatusChanged);
    void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
      {
               if (myTreeView.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
          {
              //the custom logic goes here
              //When the item is a direct child of the TreeView:
              tvAssetOverview.ItemContainerGenerator.ContainerFromItem(dataItem);
        
             //When the item is a descendant of the TreeView (i.e. child of a child...)
            tvAssetOverview.ContainerFromItemRecursive(dataItem);
          }
      }

    After you get the items container you need you should be able to set the DefaultImageSrc like you do.

    Is the ItemContainerGenerator generated when you are accessing  the containers? Also, you can go through those threads here, they might be helful.

    Let us know if this is the problem. Also, if this information doesn't help, if you can send us your project or a sample project reproducing your issues, we will investigate them further and help you implement your scenario.

    Regards,
    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