Author: Mike Shkolnik
How make a some nodes in standard TTreeview component as bold?
Me frequently ask as I in SMReport Explorer form realized selection by the bold
font some nodes.
Today I have decided to describe this very simple way (but very useful). It does
not require an override of any custom drawing methods/events, creating a new
component etc. It's a real standard way.
The standard Windows Treeview control have a few state flags (TVIS_BOLD and
TVIS_CUT in our example), due to which it's possible to reach wished.
At first, let's write the procedure SetNodeState:
1 2 procedure SetNodeState(node: TTreeNode; Flags: Integer);
3 var4 tvi: TTVItem;
5 begin6 FillChar(tvi, SizeOf(tvi), 0);
7 tvi.hItem := node.ItemID;
8 tvi.Mask := TVIF_STATE;
9 tvi.StateMask := TVIS_BOLD or TVIS_CUT;
10 tvi.State := Flags;
11 TreeView_SetItem(node.Handle, tvi);
And now we can set a wished flags:
SetNodeState(node, TVIS_BOLD) - to set the node as Bold
SetNodeState(node, TVIS_CUT) - to set the node as Cutted
SetNodeState(node, TVIS_BOLD or TVIS_CUT) - to set the node as Bold and Cutted
SetNodeState(node, 0) - to set a node as normal