This is a migrated thread and some comments may be shown as answers.

2011 Q2 Treeview - how assigning ImageKey on nodes?

2 Answers 55 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Volkan
Top achievements
Rank 1
Volkan asked on 08 Aug 2011, 10:14 PM
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 Answers, 1 is accepted

Sort by
0
Volkan
Top achievements
Rank 1
answered on 10 Aug 2011, 12:38 PM
I found it, i use the NodeFormatting event to assign the icon

Volkan
0
Stefan
Telerik team
answered on 11 Aug 2011, 11:45 AM
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 >>

Tags
Treeview
Asked by
Volkan
Top achievements
Rank 1
Answers by
Volkan
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or