1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Display "Bold" Items in the TTreeView component

By Zarko Gajic, About.com

TreeView Items with Bold Captions

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) ;

Delphi tips navigator:
» TListBox with Radio Buttons
« How to Access a TRadioButton from a TRadioGroup - Disable, Change Font, etc.

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TTreeView
  6. How to Display "Bold" Items in the TTreeView Delphi component

©2009 About.com, a part of The New York Times Company.

All rights reserved.