If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

MFC Tree Control: How to disable an item?

Q: How to disable an item?

A: Tree items do not have enabled/disabled states. That means that you can stop searching for a function called 'SetItemEnabled()', because it does not exist. You have to simulate this by your own. Let's outline what you need to do in order to 'disable' an item:

You need to mark that item as 'disabled'. As the tree control itself doesn't help here, you need to reserve a flag in the underlaying structure of each item. You will use 'SetItemData()' and 'GetItemData()' to set and retrieve this structure for each item.

You need to give some visual feedback to your user that the item is disabled. The easiest solution is to use a special (grayed) icon for the item. You can refine this approach up to changing the items color or font, as presented in this CodeGuru article.

You need to prevent some operations on that item, like expanding, selecting, dragging it or dropping on it. We assume that for each item you have correctly set an underlaying data structure called 'CItemStruct', and this has a boolean member 'm_bDisabled'.