tags:

views:

41

answers:

1

hi ,

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.

A: 

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.

Sunscreen
@Sunscreen : can u provide me some sample ?
Swapnil Gupta
An example is posted here:: http://www.codeproject.com/KB/MFC/UltimateToolbox_SysInfo.aspx
Sunscreen
@Sunscreen : how passing int values to Setimage sets the image i am not able 2 understand ? how it is assigning images to it ?
Swapnil Gupta
You should import and load your bitmaps:
Sunscreen
@Sunscreen :I Have imported the images but how to load it using numbers .Pls provide me some sample.
Swapnil Gupta
Look at my updated answer.
Sunscreen
you updated answers says "You should import and load your bitmaps:"
Swapnil Gupta
Not the comment, the actual answer
Sunscreen
ya ................
Swapnil Gupta
@Sunscreen : Pls see my edited question and help me out.. thanks for your previous help
Swapnil Gupta
@Sunscreen : Thanks for your help . I got it :)
Swapnil Gupta