vlg789
vlg789

Reputation: 751

TreeView with items that have nodes icons and without icons

I have a TreeView control in a Windows C++ application that has an ImageList set.
I am trying to insert an node that does not have icon (without TVIF_IMAGE flag) 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 that possible/ supported ?

Upvotes: 3

Views: 1601

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69706

The thing is you are inserting an item with [default] image 0. You not only need -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 you your snippet (source code):

enter image description here

Upvotes: 3

rrirower
rrirower

Reputation: 4590

Try setting the image flag to -1 rather than 0;

Upvotes: 2

Related Questions