Retrieve data from treeview

5 posts, 0 answers
  1. wilson
    wilson avatar
    3 posts
    Member since:
    Aug 2011

    Posted 12 Sep 2011 Link to this post

    Hi , I have a treeview call tvAllCategory and it contain 2 header data field(id, App_SubCategory)
    how do I retrieve back treeview Item and check if it has match with the item i key in? What I trying to do is to check the item delete in my gridview whether is exist in treeview or not, if didn't exist then need to add in back to the treeview.
    below is my code

       private void gvFavorite_Deleting(object sender, Telerik.Windows.Controls.GridViewDeletingEventArgs e)
            {
                itemsToBeDeleted = e.Items;
                foreach (var itm in itemsToBeDeleted)
                {
                                   
             received null         var mytvList = tvAllCategory.ItemsSource as MyFavorite.SilverLightService.tvCategoryList;
              error here       // mytvList.App_SubCategory.Contains(itm.ToString());

                       gvFavorite.Items.Remove(itm);
                  }
    }             


    For your information below my tree hierarchy
    HEADER(ID,App_SubCategory)
    CHILD(ID,App_SubCategory,items)
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 Sep 2011 Link to this post

    Hi Wilson,

    Actually, you will not be able to work with the Items collection directly while RadGridView is in use. You may try something like follows:

    IList<Player> gridViewSource = this.playersGrid.ItemsSource as IList<Player>;

    and remove/add items from/to the gridViewSouce. 
    Furthermore, I tested the issue you reported - the fact that the ItemsSource of RadTreeView is null and I was not able to reproduce it. Please see the sample project attached and let me know whether you can get the same behavior on it.
       Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. wilson
    wilson avatar
    3 posts
    Member since:
    Aug 2011

    Posted 15 Sep 2011 Link to this post

    Not sure is it work or not, but now I'm trying to add in some items into the treeview but not able to get around, could you do me a favor show me some example? how to get the treeview header B and add new child into it? Thanks in advance.

    Header
    A
        - Child1
        - Child2
    B
        - Child1
        - Child2
  5. wilson
    wilson avatar
    3 posts
    Member since:
    Aug 2011

    Posted 15 Sep 2011 Link to this post

    Hi,
      I was successfully add in child item but could you show me a way on how to create new header for the tree view? how to create new header called C and bind back to the tree view?

    Header
    A
        - Child1
        - Child2
    B
        - Child1
        - Child2
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Sep 2011 Link to this post

    Hi Wilson,

     Please check out the modified solution and note that an ItemTempalte is used in the RadTreeView. This is the way to bind the Name of the Player two way so that a dynamic change in the Player reflects the UI. Please let us know if you need further assistance.

    Regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner