Reputation: 8941
I want to apply different images to different nodes in my MFC Treeview ? Currently i have have applied one image to my treeview root node now i want to apply different image to subnodes and how to expand all nodes in treeview , once i expand one node other get collapsed..
Currently i am doing like this :
CImageList *m_pNASImageList;
CBitmap m_objRootImg;
m_objRootImg.LoadBitmap(IDB_TREEVIEWROOTIMG);
m_objNASFolderImg.LoadBitmap(IDB_NASFOLDERIMG);
m_RootImageList = new CImageList();
m_RootImageList->Create(16,16,ILC_COLOR8,1,1);
m_RootImageList->Add(&m_objRootImg,RGB(250,190,79));
m_RootImageList->Add(&m_objNASFolderImg,RGB(250,190,79));
m_pTreeview->SetImageList(m_RootImageList,TVSIL_NORMAL);
HTREEITEM Htvi = m_pTreeview->InsertItem("NAS1", hparentitem);
m_pTreeview->SetItemImage(Htvi,1,1);
m_pTreeview->InsertItem("Animation", Htvi);
m_pTreeview->InsertItem("StoryBoard", Htvi);
I have loaded one image for my root and one for "NAS1" , how to load for animation & Storyboard what values i should give i have taken a third image ...
Any help is highly appreciated. Thanks.
Upvotes: 1
Views: 3316
Reputation: 3564
You can use BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage); it within CTreeCtrl class.
UPD: Import your bitmaps in your resource pain and load them:
CBitmap m_Bitmap1, m_Bitmap2, m_Bitmap3, m_Bitmap4;
m_Bitmap1.LoadBitmap(IDB_BITMAP1);
m_Bitmap2.LoadBitmap(IDB_BITMAP9);
m_Bitmap3.LoadBitmap(IDB_BITMAP10);
m_Bitmap4.LoadBitmap(IDB_BITMAP8);
Create your image list for your tree: CImageList* m_ImageListTree;
m_ImageListTree = new CImageList;
m_ImageListTree->Create(IDB_BITMAP1, 16, 1, RGB(255, 255, 255));
m_ImageListTree->Add(&m_Bitmap2, RGB(255, 255, 255));
m_ImageListTree->Add(&m_Bitmap3, RGB(255, 255, 255));
m_ImageListTree->Add(&m_Bitmap4, RGB(255, 255, 255));
Set your image list with your tree:
MyTree->SetImageList(m_ImageListTree, 0);
Now you can use ints from 0 to 3 for the 4 loaded images.
Upvotes: 2