Vicky
Vicky

Reputation: 113

CTreeCtrl expand and collapse icons not working

I have created class inherit from CtreeCtrl name CMytreeCtrl in mfc visual studio 2010 professional edition CMytreeCtrl obTreeCtrl; I would like to display different icon , when expanding a particular node as follows:-

m_imageList.Create (16, 16, ILC_COLOR32, 1,4);   
m_bitmap.LoadBitmap(IDB_BITMAP5);

m_imageList.Add(&m_bitmap, RGB(255,0,255));
SetImageList (&m_imageList, TVSIL_NORMAL);

SetItemImage(hTreeItemRoot,0,0);//parent node
SetItemImage(hTreeItem,1,2) // child node

So if I expand the child node image index no 2 is used for selected image index otherwise image index no 1 is displayed. I am able to display icon no 1 in normal state, but when I exand the same treeItem, it is not changing the icon.

Upvotes: 0

Views: 660

Answers (1)

Flaviu_
Flaviu_

Reputation: 1346

If you want to change the icon of the tree item, you need to setup at least 2 icons on your CImageList.

MyTreeCtrl.SetItemImage(hItem, 0, 0);  // for first icon
MyTreeCtrl.SetItemImage(hAnotherItem, 1, 1);  // for second icon

and the place where you setup this is reflection of TVN_ITEMEXPANDED message: https://learn.microsoft.com/en-us/windows/win32/controls/tvn-itemexpanded

Upvotes: 1

Related Questions