Solved

How to disable a item in the treectrl?

Posted on 2002-06-20
5
915 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sum13 challenge 24 90
has22 challenge 11 80
Execute multiple curl cmds with sleep and send output to file 10 89
unix example issues 18 76
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

22 Experts available now in Live!

Get 1:1 Help Now