Solved

How to disable a item in the treectrl?

Posted on 2002-06-20
5
902 Views
Last Modified: 2013-11-20
Hi,
I wanna disable a item in the treectrl. But after a search in MSDN, I can't find any answer. The treectrl item state contains no flag for disabling. So how can I do?

Any comment is greatly appreciated.

Lite
0
Comment
Question by:Lite
5 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 7098351
Hi Lite,

What exactly do you mean with "disabling a treectrl item"?
Make it unselectable, invisible, unexpandable,...?
0
 

Author Comment

by:Lite
ID: 7099804
I just want to make it unselectable. Thanks!
0
 
LVL 7

Accepted Solution

by:
peterchen092700 earned 50 total points
ID: 7100155
The tree control by default does not provide the functionality to disable an item. However, you can achieve that by some customizations.

To make an item non-selectable, you can use the TVN_SELCHANGING and TVN_SELCHANGED notifications.

The first one informs you about a selection change to happen (and you can cancel it), the other one informs you that a selection change just happened.

When designing the behavior, you should make sure that keyboard usage will still be possible. The easiest approach - canceling all selection changes that go to an item that is disabled - will for sure break keyboard usage.

If you also want to change the appearance of the disabled item(s), you should explore the CustomDraw notifications of the tree control

I hope this gives you some point to start, if you need more information just ask.
0
 
LVL 4

Expert Comment

by:mblat
ID: 7104399
Well, if you are willing to everwrite CTreeCtrl and create you custom CMyTreeControl then you can do the following:

void CMyTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags=0;
HTREEITEM hItem = HitTest(point,&uFlags);
   
    if(hItem)
    {
        if(!IsItemEnabled(hItem))
            return;
    }
   
    CTreeCtrl::OnLButtonDown(nFlags, point) ;
}

You also may have to overwrite OnKeyDown, OnLButtonDblClk, OnRButtonDown etc....


Hope it helps...
0
 

Author Comment

by:Lite
ID: 7112873
Thanks, everybody!

overflow
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 150
if loop error 4 77
iSeries DB2 Query 2 84
only14 challenge 19 64
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now