TreeView with elements that have node icons and no icons

I have a TreeView control in a Windows C ++ application in which ImageList is installed .
I am trying to insert a node that does not have an icon (without TVIF_IMAGE), but the icon is still displayed.

    TVINSERTSTRUCT tvis = { 0 };
    tvis.hParent = hParent;
    tvis.hInsertAfter = hInsertAfter;
    tvis.item.mask = TVIF_TEXT;
    tvis.item.pszText = (LPTSTR) lpszItem;
    tvis.item.iImage = 0;
    tvis.item.iSelectedImage = 0;
    tvis.item.state = nState;
    tvis.item.stateMask = nStateMask;
    tvis.item.lParam = lParam;
    ::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);

Is this possible / supported?

+3
source share
2 answers

The fact is that you are inserting an element with an image [default] 0. You need not only -1, but you also need TVIF_IMAGE:

    tvis.item.mask = TVIF_TEXT | TVIF_IMAGE;
    tvis.item.iImage = -1;

Here is the effect of this change compared to your snippet ( source code ):

enter image description here

+3
source

Try setting the image flag to -1, not 0;

+2

All Articles