Forum > LCL

[SOLVED] selected ImageIndex in a TShellTreeView

(1/1)

petevick:
I'm using.....

--- 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";}};} ---  n:= ShellTreeView1.Selected.ImageIndex;... in a procedure to get the image index in the currently selected node of a TShellTreeView, but n is always -1, and I know that it should be more than 0. Is there another way to get the currently selected node image index ??

petevick:
This is crazy, the following....

--- 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";}};} ---  Str:= ShellTreeView1.Selected.Text;...gives the correct selected folder name, even.....

--- 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";}};} ---  Str:= ShellTreeView1.Selected.GetTextPath;....gives the correct path to the folder, and I know the same folder also has an ImageIndex of 10, but, as above......

--- 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";}};} ---  n:= ShellTreeView1.Selected.ImageIndex;....gives -1, what the hell  >:(

wp:
Is this for Windows or Mint? (Both are in your signature).

In Windows, the icons are drawn in the TShellTreeView by calling OS routines, without explicitely using the ImageList and ImageIndex and SelectedIndex properties. 
If you attach an ImageList to the tree and define an ImageIndex/SelectedIndex for each node, and set UseBuiltinIcons to false, then you have full control over the icons displayed. This also happens in Linux by default where the Windows solution could not be applied.

petevick:

--- Quote from: wp on May 10, 2024, 07:02:54 pm ---Is this for Windows or Mint? (Both are in your signature).

In Windows, the icons are drawn in the TShellTreeView by calling OS routines, without explicitely using the ImageList and ImageIndex and SelectedIndex properties. 
If you attach an ImageList to the tree and define an ImageIndex/SelectedIndex for each node, and set UseBuiltinIcons to false, then you have full control over the icons displayed. This also happens in Linux by default where the Windows solution could not be applied.

--- End quote ---
It's for both Linux and Windows, although I've not yet tested it Windows, the above is happening in Linux.

I have OnGetImageIndex and OnGetSelectedIndex set up (see below, the selected folder has an ImageIndex of 10), which is why I know what the selected imageindex should be

petevick:
Mentioning OnGetSelectedIndex gave me a clue, I've set a global variable in the OnGetSelectedIndex procedure....

--- 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";}};} ---  ImgIndex:= Node.SelectedIndex;...this obviously updates the variable when a different node is selected, that together with an Application.ProcessMessages after I change the ShellTreeView1 path elsewhere gives me the correct ImageIndex number I was after  ;D

Phewwww  :)

Navigation

[0] Message Index

Go to full version