Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a treeview, which is binding categories and subcategories from database.

I want to display an icon (image) on left side of the treeview. For example, in treeview I have categories such as amana tool as a parent node and the router bits as child node of amana tool. So, in database I have icon of amana tool as well as icon of router bits. Now, I am able to show categories (amana tool) only in treeview. But, I need that left side should show the icon of the related categories and then categories name(amana tool).


Note: The icon should bind from database but it should not be static icon because I need to show more than 100 categories and the icon existing in database.

Please help me out.
Posted
Updated 11-Jul-13 2:30am
v2

1 solution

Hi,
You have to define a tree view item as a seperate class. In that class define propertys like header, url and image source. see below code for more understand.
Define a tree view item as class name MenuItem.
Code:

C#
MenuItem Class:
public class MenuItem
    {
        public string Header { get; set; }
        public string Url { get; set; }
        public BitmapImage ImageSource { get; set; }
        public List<menuitem> SubMenuItems { get; set; }
    }

List <menuitem> MenuItems = new List<menuitem>();
MenuItems.Add(
                    new MenuItem()
                    {
                        Header = "Display Name",
                        Url = "NavigationUrl",
                        ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("ur image url from database", UriKind.RelativeOrAbsolute)),
                                            });
//Bind menitems list to ur treeview 
tvLeftMenu.ItemsSource = MenuItems;

Thanks
Anil
 
Share this answer
 
v2
Comments
christhuxavier 11-Jul-13 9:09am    
hi bitmapimage is throwing error in c# asp.net.
Anilkumar2vvv 11-Jul-13 9:35am    
please post the error ...
Anilkumar2vvv 11-Jul-13 9:57am    
use this reference using System.Windows.Media.Imaging;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900