Recent

Author Topic: [SOLVED] selected ImageIndex in a TShellTreeView  (Read 1219 times)

petevick

  • Sr. Member
  • ****
  • Posts: 427
[SOLVED] selected ImageIndex in a TShellTreeView
« on: May 10, 2024, 12:50:50 pm »
I'm using.....
Code: Pascal  [Select][+][-]
  1.   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 ??
« Last Edit: May 11, 2024, 09:47:29 am by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: selected ImageIndex in a TShellTreeView
« Reply #1 on: May 10, 2024, 06:32:48 pm »
This is crazy, the following....
Code: Pascal  [Select][+][-]
  1.   Str:= ShellTreeView1.Selected.Text;
...gives the correct selected folder name, even.....
Code: Pascal  [Select][+][-]
  1.   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  [Select][+][-]
  1.   n:= ShellTreeView1.Selected.ImageIndex;
....gives -1, what the hell  >:(
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 13401
Re: selected ImageIndex in a TShellTreeView
« Reply #2 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.

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: selected ImageIndex in a TShellTreeView
« Reply #3 on: May 10, 2024, 07:47:28 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.
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
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: selected ImageIndex in a TShellTreeView
« Reply #4 on: May 10, 2024, 08:13:27 pm »
Mentioning OnGetSelectedIndex gave me a clue, I've set a global variable in the OnGetSelectedIndex procedure....
Code: Pascal  [Select][+][-]
  1.   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  :)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

 

TinyPortal © 2005-2018