Solved

Disable few seleceted items in CTreeCtrl

Posted on 2011-09-23
5
1,412 Views
Last Modified: 2012-05-12
Hi, can you please tell how we can disable few CTreeCtrl items and few of them enable.
I shouldnt be able to perform any action on those disabled items, i shouldnt be able to check it's check box, i shouldnt be able to edit those items too.

I do not want to use this function:      
SetItemStateEx(l_hTempItem, TVIS_EX_DISABLED);


Regards and thanks for the help
 
0
Comment
Question by:RsTVS
  • 3
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
mrwad99 earned 500 total points
ID: 36598281
You could keep a list of the HTREEITEMs that you wish to "disable"; then, whenever the user clicks on the tree control, you get the item that was clicked on, comparing it to the items in your list.  If the item exists in the list, then you prevent the click from going through.

I believe the function you want is OnNMClicked or similar...
0
 

Author Comment

by:RsTVS
ID: 36598385
Is there any other way of doing it other than storing the list of items to be disabled. something like setting the state of HTREEITEM, by setting some flags in SetItemState(),

0
 
LVL 19

Expert Comment

by:mrwad99
ID: 36598449
The checkboxes are not actual checkboxes, but are in fact images from an image list; you can prove this by using Spy++ on a tree control with checkboxes.  Therefore, there is no "control" as such to "disable".  Your best bet is to create the illusion of a "disabled" checkbox, by perhaps using a three-state-checkbox tree control, like this one:

http://www.codeguru.com/cpp/controls/treeview/misc-advanced/article.php/c3983/TreeView-with-Three-State-Checkboxes.htm

You still need to keep a list of the items to disable though, so can programatically alter the image being shown to the "disabled" one.

HTH
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 36598467
Oh, and to prevent the editing of the label text, you need to trap TVN_ITEMCHANGING, and return TRUE to prevent the edit from being initiated.  But again, you still need to keep a list of the items you don't want to be edited.
0
 

Author Closing Comment

by:RsTVS
ID: 36598622
I have tried this method of keeping a list of HTREEITEMS and over rided ON_WM_LBUTTONDOWN, i have omitted defalut handling of lbutton down of CTreeCtrl for all the tree items which i want to be disabled,


Thanks for the help anyway.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

809 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