tRzTreeView change node font

Viewing 1 reply thread
  • Author
    Posts
    • #2534
      Jay Wright
      Participant

        I need to be able to change the font color and style on certain nodes in the TreeView.  I’ve searched the internet without any luck.  Can someone point me in the correct direction?  TIA

      • #2538
        Ray Konopka
        Keymaster

          Hi Jay,

          The TRzTreeView is a descendant of the TTreeView and inherits the same properties and events. Specifically, you can do some customizations by handle the OnAdvancedCustomDrawItem event.

          For example, I created a test app where I dropped a TRzTreeView on the form. I then added a FormCreate event handler, and an event handler for the tree view’s OnAdvancedCustomDrawItem event.

          procedure TForm11.FormCreate(Sender: TObject);
          var
            Node: TTreeNode;
          begin
            Node := RzTreeView1.Items.Add( nil, 'One' );
            RzTreeView1.Items.AddChild( Node, 'AAAA' );
            RzTreeView1.Items.AddChild( Node, '1111' );
          
            Node := RzTreeView1.Items.Add( nil, 'Two' );
            RzTreeView1.Items.AddChild( Node, 'BBBB' );
            RzTreeView1.Items.AddChild( Node, '2222' );
          
            Node := RzTreeView1.Items.Add( nil, 'Three' );
            RzTreeView1.Items.AddChild( Node, 'CCCC' );
            RzTreeView1.Items.AddChild( Node, '3333' );
          
            RzTreeView1.FullExpand;
          end;
          
          procedure TForm11.RzTreeView1AdvancedCustomDrawItem( Sender: TCustomTreeView; Node: TTreeNode;
                                                               State: TCustomDrawState;
                                                               Stage: TCustomDrawStage;
                                                               var PaintImages, DefaultDraw: Boolean);
          begin
            if Node.Text = 'AAAA' then
              RzTreeView1.Canvas.Font.Color := clRed
            else if Node.Text = 'BBBB' then
              RzTreeView1.Canvas.Font.Color := clBlue
            else
              RzTreeView1.Canvas.Font.Color := clBlack;
          end;

          When you run the app, you will see the AAAA and BBBB in their respective colors.
          Hope this helps.

          Ray

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.