简体   繁体   中英

Remove image from certain treeview item?

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 :

在此处输入图片说明

If I select another item the image suddenly reappears:

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM