Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I made a CTreeCtrl on runtime and I want, when i click a button, to select only a part from an item. Is any way to do this?
Posted
Comments
Sergey Alexandrovich Kryukov 28-Mar-13 13:23pm    
What do you mean by "to select only a part from an item". Tree controls have nodes. What do you want to achieve?
—SA
manomano 28-Mar-13 16:01pm    
From a node goes multiple items, which have, on their turn characters. When i click a button I want to make more visible, using a backcolor, only few characters in a item.
Sergey Alexandrovich Kryukov 28-Mar-13 16:28pm    
Those "items" are also nodes, always. You can achieve what you need by custom draw of the item or the whole thing.
—SA

1 solution

If you want to detect a click at a finer grain than a single item and paint only part of an item as selected then you're going to need to override both selection and painting for the TreeControl.
You'll need to look up the details of what is called CustomDraw and if that is not enough you may have to resort to OwnerDraw although I don't think I've ever seen a fully OwnerDraw Tree Control, that is a lot of hard work.

For the partial item click detection you'll need to hook into the ordinary item based click detection, then get the exact position the mouse was at when the message was sent which is available although I can't immediately remember how you get it.
Then you'll need to do the sub item calculation yourself probably based on information cached when you did the custom item painting.
You'll also need to store a set of selection states, 1 bit per sub item will probably do, alongside your other item data so that you know whether to paint each sub item as selected or unselected when you get a paint request.

You'll definitely need a pile of sample code to get all the right things in the right places for a Custom Draw Tree Control but I'm sure there are helpful CP articles like this one [^]to get you started.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Mar-13 16:29pm    
My 5. Too bad, in 1st version of OP's question the goal wasn't clear at all, and not the question is still too bad... :-(
—SA
nv3 28-Mar-13 18:11pm    
My 5 as well. I think you guessed very well what OP actually wanted. Happy easter, folks!

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