Forum > LCL

How to show node image when a TTreeView item is selected

(1/2) > >>

tintinux:
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:
Probably via property "SelectedIndex"   ... eg.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---       aNode.ImageIndex := 4;       aNode.SelectedIndex := 4;     // or:  aNode.SelectedIndex := aNode.ImageIndex;

tintinux:
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:

--- Quote from: tintinux on October 04, 2022, 03:42:37 pm ---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.

--- End quote ---
The solution from @d7_2_laz is just for such a case.

d7_2_laz:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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?

Navigation

[0] Message Index

[#] Next page

Go to full version