Author: Tomas Rutkauskas
I would like to write the text of each node in a TTreeview by including the text in
the standard way with a trailing number written in bold and color blue.
Answer:
This is a code snippet of a descendant of a TTreeView that handles the bold state
of a treenode:
1 2 function TTreeView1.GetNodeBoldState(Node: TTreeNode): boolean;
3 var4 TVItem: TTVItem;
5 begin6 result := false;
7 ifnot Assigned(Node) then8 exit;
9 with TVItem do10 begin11 mask := TVIF_STATE;
12 hitem := Node.ItemId;
13 result := TreeView_GetItem(Node.Handle, TVItem) and ((State and TVIS_BOLD) <>
14 0);
15 end;
16 end;
17 18 procedure TTreeView1.SetNodeBoldState(Node: TTreeNode; value: boolean);
19 var20 TVItem: TTVItem;
21 begin22 ifnot Assigned(Node) then23 exit;
24 fillchar(TVItem, sizeof(TVItem), 0);
25 with TVItem do26 begin27 mask := TVIF_STATE or TVIF_HANDLE;
28 hitem := Node.ItemId;
29 StateMask := TVIS_BOLD;
30 if value then31 State := TVIS_BOLD;
32 TreeView_SetItem(Node.Handle, TVItem);
33 end;
34 end;