Solved

How to disable a item in the treectrl?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 94
lucky13 challenge 11 154
scoreUp challenge 14 63
Annoying "thing" blocks my view 4 115
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…
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 …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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