Solved

How to disable a item in the treectrl?

Posted on 2002-06-20
5
951 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

688 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