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

How to Display "Bold" Items in the TTreeView component

By , About.com Guide

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

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.