Display different icons to different nodes
-
How can I show different icons/images to different nodes in a TreeListView? I am referring the example http://blogs.msdn.com/atc_avalon_team/attachment/541206.ashx[^] I want to show one image to all root nodes and another to all child nodes.
Jayant D. Kulkarni
-
How can I show different icons/images to different nodes in a TreeListView? I am referring the example http://blogs.msdn.com/atc_avalon_team/attachment/541206.ashx[^] I want to show one image to all root nodes and another to all child nodes.
Jayant D. Kulkarni
Look into WPF DataTemplates. You can use a TemplateSelector to select different templates based on some code in the TemplateSelector or you can use a DataTrigger in the DataTemplate to change which icon is displayed.
Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
Look into WPF DataTemplates. You can use a TemplateSelector to select different templates based on some code in the TemplateSelector or you can use a DataTrigger in the DataTemplate to change which icon is displayed.
Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
Thanks Karl. It worked for me. One more question, can we have separate icon for each node? I am asking because currently I am assigning image depending upon the HasItem property of treenode. In future I will like to show different icons for each node. Is it possible?
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET
-
Thanks Karl. It worked for me. One more question, can we have separate icon for each node? I am asking because currently I am assigning image depending upon the HasItem property of treenode. In future I will like to show different icons for each node. Is it possible?
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET
Yep. :cool: Use one of the two previous methods I gave you and test against the data that is bound to the TreeV Item. Then display the icon you want. WPF makes things like this very simple for developers. Got to love WPF. :rose:
Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
-
Yep. :cool: Use one of the two previous methods I gave you and test against the data that is bound to the TreeV Item. Then display the icon you want. WPF makes things like this very simple for developers. Got to love WPF. :rose:
Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.
Thanks Karl for reply. Yes it can be done using different properties, for example check the tag value and set the image. Now I am crating a generic user control and I want these images should dynamically get assigned. So, application1 will like some another icon at root level and different icon at child node level, similarly application2 will like to use some different icons. What I will like to do is let the application using my control set the images programmatically. How can we do this?
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET
-
Thanks Karl for reply. Yes it can be done using different properties, for example check the tag value and set the image. Now I am crating a generic user control and I want these images should dynamically get assigned. So, application1 will like some another icon at root level and different icon at child node level, similarly application2 will like to use some different icons. What I will like to do is let the application using my control set the images programmatically. How can we do this?
Jayant D. Kulkarni Brainbench Certified Software Engineer in C#1.1, C# 2.0, ASP.NET, .NET Framework and ADO.NET
This a SUPER easy in WPF. Read up on
Styles
andControlTemplates
. There are a lot of WPF articles here on Code Project that cover this topic. This is one of the foundational powers that WPF delivers. You can simply write one Style, place it in application scope and all Tree controls can use it. The possibilities are endless.Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.