Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello everyone!

I would like to start by saying thanks to everyone who takes some time to view this thread and try to help.


I have made a tree view control in dialog box, using resource editor.

I have set the checkbox style with SetWindowLongPtr( ... ) function.

Every node has checkbox, yet I need only some to have checkbox, and some to have nothing standing next to their text.

Can this be achieved by subclassing, and if it can, please give me some pointers or links, possibly sample code or tutorials.

If it can't be done by subclassing, then please point me to the right direction on how to do it ( maybe custom draw or perhaps superclassing ? ).

I work in MS Visual Studio Express 2008, on Windows XP, in C++, using pure WIN32 API.

Thank you very very much!
Posted
Updated 15-Jul-13 12:31pm
v2
Comments
Sergey Alexandrovich Kryukov 15-Jul-13 20:00pm    
Do you want to hide only a check box (why hide? isn't disable status much better? the difference is: checked/unchecked status is still shown?), or, say, the whole row?
—SA
MyOldAccount 16-Jul-13 14:10pm    
Sorry for late reply, let me try to explain this:
*****************************************************

Lets say that tree view has nodes like this:

[] Text of node( this node can be checked )
+ Node that has children ( this node can't be checked )
|___ [] This node's child item ( this node can be checked )
|___ + Another node ( this node can't be checked )
|__ [] Child node ( this node can be checked )

*************************************

Those nodes that have symbol [] next to them can be checked/unchecked, and those nodes with symbol + can't be checked/unchecked.

I don't want to waste your time, explaining why it must be this way, but it must.

To simplify : nodes with child nodes have only + next to them, single nodes have checkbox next to them.

I hope this is clear enough, and thank you for seeing my question.

Sergey Alexandrovich Kryukov 16-Jul-13 14:28pm    
Not quite. My question was confusing, because I mistakenly used the wrong term "row". I mean: when you hide what you hide, you may hide just the check box, or the node itself. This is what I wanted to understand. Secondly, let's suppose you have to hide only the check box. If so, will you consider to make it gray (disabled) instead. Also, do the nodes with the check box have children (it would be bad for performance if you hide them)?
—SA
MyOldAccount 16-Jul-13 15:38pm    
I just want to hide checkbox, like this:

*******************

[ ] Text of first node
+ Text of second node
|__ [ ] Text of child node
|__ + Text of child node
|__ [ ] Text of child node

*************************************

Parent nodes do NOT have checkbox, only child or simple ones( ones without children ).

I will consider disabled checkbox next to parent node, yet i prefer if it would not exist at all next to the parent node ( like in the "picture" above ).

Check this out - Versatile Tree Control[^]
 
Share this answer
 
Comments
MyOldAccount 16-Jul-13 14:10pm    
Thank you, this looks promising, I will report my results as soon as possible!

It can work, but I prefer my solution.

Still, it can be done this way too, so I will accept it.

Thank you.
After OP's clarifications: one solution is to remove the node and add it again, this time with check box removed or added. If it has children, the whole child set should be preserved and restored. Second solution is to use custom draw and simulate a check box in graphics and program all required events. Invalidate the node and get check box removed (hidden), disabled, or anything.

—SA
 
Share this answer
 
Comments
MyOldAccount 17-Jul-13 6:57am    
I am interested in first option, but I need a small snippet of code to help me.

I am sorry for being a pain, but this is my first time using tree view control, and it is hard for me since I am new to WIN32.

If you could at least give me a bit more detailed instructions, I would highly appreciate it.

I have a parent node defined like this:
---------------------------------------------
TVINSERTSTRUCT tvis = {0};

memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

tvis.item.mask = TVIF_TEXT;
tvis.item.pszText = L"Јавне и комерцијалне делатности";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = TVI_ROOT;

HTREEITEM htiJKD = reinterpret_cast<htreeitem>( SendMessage( hwndTV, TVM_INSERTITEM, 0, reinterpret_cast<lparam>( &tvis ) ) );
--------------------------------------------------

I have tried to delete and add it again like this:
---------------------------------------------------------
// try to delete it

TreeView_DeleteItem( GetDlgItem( hwnd, IDC_TREE1 ), htiJKD );

// and add it again

memset( &tvis, 0, sizeof(TVINSERTSTRUCT) );

tvis.item.mask = TVIF_TEXT;
tvis.item.pszText = L"Јавне и комерцијалне делатности";
tvis.hInsertAfter = TVI_LAST;
tvis.hParent = TVI_ROOT;

htiJKD = reinterpret_cast<htreeitem>( SendMessage( hwndTV, TVM_INSERTITEM, 0, reinterpret_cast<lparam>( &tvis ) ) );
-----------------------------------------------------

but nothing has changed.

Please help me a bit.

Thank you!
MyOldAccount 23-Jul-13 11:05am    
It would not kill you if you sometimes provide a small snippet of code with your answers, still, simulating checkboxes is acceptable solution, so I will accept it.
Thanks for help.
Sergey Alexandrovich Kryukov 23-Jul-13 11:07am    
This is what I do: sometimes provide them. It's not killing me. This time I'm not going to do it, sorry. Please, no conditions for accepting...
—SA
MyOldAccount 23-Jul-13 11:18am    
It is OK, I have already accepted you solution.

I just said that sometimes a small snippet of code, or set of written instructions can go a long way for a beginner who asks the question.

Again, thank you for your help.

Cheers!
Sergey Alexandrovich Kryukov 23-Jul-13 11:22am    
You are very welcome.
Good luck, call again.
—SA
There are two ways somebody can do this:

One is to simulate checkboxes, as it is suggested in solutions 1 and 2, and other is to do it this way:

After creating tree view control, add an item, get this items handle, and then set items state the way it is described here:

http://stackoverflow.com/questions/17798463/is-it-possible-to-remove-some-checkboxes-from-tree-views-nodes[^]
 
Share this answer
 
v4
Comments
RajaPratap 29-May-14 2:01am    
Have you checked whether the thing that was discussed in stackoverflow works fine.
I did it but i am still visualizing the checkboxes. The same problem you had faced i am facing at present,added the checkboxes using SetWindowLongPtr as we know it is adding checkboxes to all the nodes but I am supposed to do is the parent node should not have checkboxes where the child nodes must have in a random manner .


I hope might done with pro can anyone please help me how can remove the checkboxes at the root nodes and adding checkboxes at childitems.
Hi,

Another solution, without using images, is to disable the treview check box (or better simulate that behaviour) as described here:

http://matteo72.wordpress.com/wp-admin/post.php?post=327&action=edit&message=6&postpost=v2[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900