2014-04-03 47 views
0

我有一個treeviewcheckboxes,它有imagelistTreeView_SetImageList()設置。從某些樹視圖項目中刪除圖像?

我想從沒有孩子的節點中移除圖像。我成功地去除父節點checkboxes,所以我想嘗試類似的辦法:

// 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); 

預期它不工作。起初,圖像不顯示,但該項目的文字是不是旁邊checkbox

enter image description here

如果我選擇另一項目的形象突然重新出現:

enter image description here

如果我點擊在有問題的節點上,我再次得到相同的結果,如第一張圖所示。

我的問題很簡單:

如何從一個節點中刪除圖像?

謝謝。

此致敬禮。

+0

我會說,讓項目文本左對齊比使用交錯對齊更好,因爲這會讓用戶很難快速掃描樹。 – user1793036

回答

1

您無法從單個節點中刪除圖像。一旦分配了圖像列表,即使單個節點不顯示列表中的圖像,TreeView也會爲所有節點上的列表圖像保留相同的空間。

要做你在問什麼,根本不要分配圖像列表,然後custom-drawn the nodes使它們出現,但是你想要的。

+0

樹形視圖可以在純Winapi中自主繪製嗎?我沒有在MSDN文檔中看到'TVS_OWNERDRAW'或類似的樣式。 Matbe是我唯一的選擇是自定義繪製?謝謝。最好的祝福。 – AlwaysLearningNewStuff

+0

是的,你可以[Custom Draw a TreeView](http://msdn.microsoft.com/en-us/library/windows/desktop/ff919569(v = vs.85).aspx#list_tree)。 –