How to show node image when a TTreeView item is selected lazarus / 31-LCL ---------------------------------------------------------------------- tintinux · 2022-10-04 11:58 Hi I display node images, using the property "Images" of my TreeView. When a node is selected the image disappear on this node. Is it possible to prevent this ? Thanks ---------------------------------------------------------------------- d7_2_laz · 2022-10-04 13:02 Probably via property "SelectedIndex"   ... eg. 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        aNode.ImageIndex := 4;       aNode.SelectedIndex := 4;     // or:  aNode.SelectedIndex := aNode.ImageIndex; ---------------------------------------------------------------------- tintinux · 2022-10-04 13:42 No, this is not a solution. I was probably not clear enough. The images are correctly displayed on all tree nodes, but when a node is selected (either by code or by UI), the image is not visible. ---------------------------------------------------------------------- ASerge · 2022-10-04 14:46 Quote from: tintinux on October 04, 2022, 03:42:37 pmThe images are correctly displayed on all tree nodes, but when a node is selected (either by code or by UI), the image is not visible. The solution from @d7_2_laz is just for such a case. ---------------------------------------------------------------------- d7_2_laz · 2022-10-04 15:05 tintinux, i don't know with which platform and Lazarus version you are working .. I can speak for Windows only - no such problem here -; and in this situation i would try something like: 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 procedure TForm1.TreeView1SelectionChanged(Sender: TObject);begin   ShowMessage(inttostr(TreeView1.Selected.SelectedIndex));end; Now, here either you see a "-1" = no image assigned = nothing will be displayed or can inspect the image the SelectedIndex does point to within the ImageList assigned. Something special with this image? ---------------------------------------------------------------------- tintinux · 2022-11-16 17:09 Hi I'm on Linux Ubuntu. My issue is only about the displayed image : when the node is selected, the image is not shown, when the node is not selected the image is shown. I have no problem with SelectedIndex. I have made a small example attached. Maybe you will see easier the issue. Thanks ---------------------------------------------------------------------- tintinux · 2022-11-16 17:14 Quote from: d7_2_laz on October 04, 2022, 05:05:00 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.TreeView1SelectionChanged(Sender: TObject);begin   ShowMessage(inttostr(TreeView1.Selected.SelectedIndex));end; Now, here either you see a "-1" = no image assigned = nothing will be displayed You are wrong, I think. Selected.ImageIndex (instead of Selected.SelectedIndex) returns the image associated to the node. In my case it doesn't change after node creation. ---------------------------------------------------------------------- wp · 2022-11-16 17:32 Completed your code so that it is working: 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 procedure TForm1.FormCreate(Sender: TObject); begin  TreeView1.Items.AddChild(TreeView1.Items.Add(nil, 'Node 1'), 'Node 2');  Treeview1.Items[0].ImageIndex:= 0;  Treeview1.Items[1].ImageIndex:= 0;  TreeView1.Items[0].SelectedIndex := 0;  TreeView1.Items[1].SelectedIndex := 0;end; See: https://lazarus- ccr.sourceforge.io/docs/lcl/comctrls/ttreenode.selectedindex.html, or https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.ComCtrls.TTree Node.SelectedIndex ---------------------------------------------------------------------- tintinux · 2022-11-16 17:36 Thanks !