سؤال

I have a treeview with checkboxes and it has imagelist set with TreeView_SetImageList().

I am trying to remove image from nodes that do not have children. I was successful in removing checkboxes from parent nodes, so I thought to try the similar approach:

// add an item

TVINSERTSTRUCT tvis = {0};

tvis.item.mask = TVIF_TEXT //  | TVIF_IMAGE;

//   tvis.item.iImage = -1;           // I thought this will work
//   tvis.item.iSelectedImage = -1;   // but it does not work at all

tvis.item.pszText = L"Some text";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = TVI_ROOT;

htItem = reinterpret_cast<HTREEITEM>( SendMessage( hwndTV, 
    TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>( &tvis ) ) );

// remove image

TVITEM tvi;

tvi.hItem = htItem;
tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvi.iImage = -1;
tvi.iSelectedImage = -1;

TreeView_SetItem( hwndTV, &tvi );

It does not work as expected. At first the image is not shown, but the item text is not next to the checkbox:

enter image description here

If I select another item the image suddenly reappears:

enter image description here

If I click on the problematic node again I get the same result, as shown in the first picture.

My question is simple:

How do I remove an image from a node?

Thank you.

Best regards.

هل كانت مفيدة؟

المحلول

You cannot remove images from individual nodes. Once you have an image list assigned, the TreeView reserves space for the list's images on all nodes equally, even if individual nodes do not display images from the list.

To do what you are asking, do not assign the image list at all, and then custom-drawn the nodes to make them appear however you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top