Mega Code Archive

 
Categories / Delphi / VCL
 

How to Display Bold Items in the TTreeView Delphi component

Title: How to Display "Bold" Items in the TTreeView Delphi component The TTreeView Delphi component displays a hierarchical list of items, such as the headings in a document. By default (Windows drawing), all items (tree nodes) of a tree view share the same font styling. If you want to have each item of a tree view to look differently you would need to include some special owner drawing techniques. If you only want to apply *bold* to some tree items (their Captions), you can use a "special" (defined in the CommCtrl.pas unit) TreeView API. Here's a simple trick to display some of the tree items in bold: uses CommCtrl, ...; procedure BoldTreeNode(treeNode: TTreeNode; Value: Boolean) ; var treeItem: TTVItem; begin if not Assigned(treeNode) then Exit; with treeItem do begin hItem := treeNode.ItemId; stateMask := TVIS_BOLD; mask := TVIF_HANDLE or TVIF_STATE; if Value then state := TVIS_BOLD else state := 0; end; TreeView_SetItem(treeNode.Handle, treeItem) ; end; //Usage BoldTreeNode(TreeView1.Items[1], True) ; BoldTreeNode(TreeView1.Items[6], True) ;