[SOLVED] Change the Font Style of a specific TTreeNode lazarus / 31-LCL ---------------------------------------------------------------------- DeBritto · 2015-12-11 12:14 Hi everybody, Is it possible to change the Fonte Style of a specific TTreeNode of a TTreeview? How to do it? I tried OnCustomDraw event but that changes all nodes of my Treeview. Here is the piece of code I'm using to populate my TTreeview: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                // Factors not linked to modalities                 with Main.TVM odalitiesAndFactors.Items.Add(nil,DataModule_SmCube.SQLQuery_SmCube.Fi eldByName('name').AsString) do                 begin                  Selected   := True;                    ImageIndex := 0;  // Put icons on Treeview items                    SelectedIndex := 0;                  //Font.Style := [fsBold];                 end;  Best regards ---------------------------------------------------------------------- Zaxxon · 2015-12-14 09:52 If the specific node has a unique text, you can do the folllowing: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    TreeView1: TTreeView;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;    State: TCustomDrawState; var DefaultDraw: Boolean);  private    DFont,NFont:TFont;    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var Node:TTreeNode; begin  Node:=Self.TreeView1.Items.AddChild(nil,'test');  Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));  Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));  Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));  Self.Tree View1.Items.AddChild(Node,IntToStr(Random(1000)));end; procedure TForm1.FormCreate(Sender: TObject);begin  DFont:=TFont.Create;  NFont:=TFont.Create;  DFont.Assign(Self.TreeView1.Font);  NFont.Assign(Self.TreeView1.Font);  NFont.Name:='Gabriola';  NFont.Size:=12;end; procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);begin  if Node.Text='test' then Self.TreeView1.Font.Assign(NFont)  else Self.TreeView1.Font.Assign(DFont);  Node.Height:=Self.TreeView1.DefaultItemHeight;end; I've tested it a little and I see it needs some improvements. Still it allmost works. Added Node.Height:=Self.TreeView1.DefaultItemHeight; now it seem to work better. ---------------------------------------------------------------------- DeBritto · 2015-12-15 01:40 Perfect Zaxxon, Works like a charm! I could never imagined how to do this... Thank you so much. Best regards from Brazil ---------------------------------------------------------------------- Zaxxon · 2015-12-15 22:59 Don't forget to free DFont and NFont in the FormDestroy event. Also a faster way to check the node can be to use another node variable and assign it to the node to check for instead of using the node text. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     type         { TForm1 }           TForm1 = class(TForm)        Button1: TButton;        TreeView1: TTreeView;        procedure Button1Click(Sender: TObject);        procedure FormCreate(Sender: TObject);        procedure TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;          State: TCustomDrawState; var DefaultDraw: Boolean);      private        DFont,NFont:TFont;      CNode:TTreeNode;        { private declarations }      public        { public declarations }      end;         var      Form1: TForm1;      implementation         {$R *.lfm}         { TForm1 }         procedure TForm1.Button1Click(Sender: TObject);         var Node:TTreeNode;         begin      Node:=Self.TreeView1.Items.AddChild(nil,'test');      CNode:=Node;    Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));      Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));      Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));      Self.TreeView1.Items.AddChild(Node,IntToStr(Random(1000)));    end;       procedure TForm1.FormCreate(Sender: TObject);    begin      DFont:=TFont.Create;      NFont:=TFont.Create;      DFont.Assign(Self.TreeView1.Font);      NFont.Assign(Self.TreeView1.Font);      NFont.Name:='Gabriola';      NFont.Size:=12;    end;         procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;      Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);    begin      if Node=Self.CNode then Self.TreeView1.Font.Assign(NFont)    else Self.TreeView1.Font.Assign(DFont);      Node.Height:=Self.TreeView1.DefaultItemHeight;    end;