Click here to Skip to main content
13,047,502 members (64,102 online)
Rate this:
Please Sign up or sign in to vote.
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 11-Jul-13 1:10am
Updated 11-Jul-13 2:30am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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>();
                    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;

christhuxavier 11-Jul-13 9:09am
hi bitmapimage is throwing error in c#
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100