?
Solved

How to disable a item in the treectrl?

Posted on 2002-06-20
5
Medium Priority
?
965 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 200 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

743 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