2011 Q2 Treeview - how assigning ImageKey on nodes?

3 posts, 0 answers
  1. Volkan
    Volkan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 08 Aug 2011 Link to this post

    Hi i fill the treeview via code and works well, but i need a way to asign a icon from a assigned imagelist on the nodes.
    The Data assignemend is:

    - ChildMember = id
    - DisplayMember = Label
    - ParentMember = pid
    - Tag = ImageKey
    - ValueMember = ImageKey

    I have tested with the tag and the valuemember fields without success, the tag field is allways empty :(

    I have tryed to assign the CollectionChanged event, ut it does not fire when the datasource is bound... !?

     

    radTreeView1.Nodes.CollectionChanged  += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(Nodes_CollectionChanged); 
              List<TreeItem> items = new List<TreeItem>();
              {
                  TreeItem t1 = new TreeItem();
                  t1.id = 1;
                  t1.Label = "Home";
                  t1.ImageKey = "airplane";
                  items.Add(t1);
              }
              {
                  TreeItem t1 = new TreeItem();
                  t1.id = 2;
                  t1.pid = 1;
                  t1.Label = "Level 2";
                  t1.ImageKey = "comments";
                  items.Add(t1);
              }
              radTreeView1.ValueMember = "id";
              radTreeView1.ParentMember = "pid";
              radTreeView1.DisplayMember = "Label";
              radTreeView1.Tag = "ImageKey";
              radTreeView1.DataSource = items;

     

     

     

    void Nodes_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
           {
                   RadTreeNode n = ((RadTreeNode)e.NewItems[0]);
                   ((RadTreeNode)e.NewItems[0]).ImageKey = n.Tag.ToString();
               
           }

    public class TreeItem
       {
           public int id { get; set; }
           public int pid { get; set; }
           public string Label { get; set; }
           public string ImageKey { get; set; }
       }

    Any help would be great
    Thx
    Volkan Senguel

  2. Volkan
    Volkan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 10 Aug 2011 Link to this post

    I found it, i use the NodeFormatting event to assign the icon

    Volkan
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 11 Aug 2011 Link to this post

    Hi Volkan,

    Thank you for writing.

    That is correct. The NodeFormatting event is the right one to assign images to RadTreeNodes. Attached you can find a sample solution demonstrating the usage of ImageList.

    I hope this helps.
     
    Regards,
    Stefan
    the Telerik team

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

Back to Top