Solved

Disable few seleceted items in CTreeCtrl

Posted on 2011-09-23
5
1,391 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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
EvenOdd challenge 10 83
GUI: DIalog Stacking and Popping in MS C++ 4 59
array6 challenfge 6 65
word0 challenge 4 54
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

12 Experts available now in Live!

Get 1:1 Help Now