1

How can I set the TreeView's selected node to the default clHighlight color when the TreeView is not focused? I tried this code in the CustomDrawItem and AdvancedCustomDrawItem events - no luck:

if (cdsSelected in State) then
  Sender.Canvas.Brush.Color := clHighlight;

Also tried the change the .HideSelection property, makes no difference, still using that very light gray color. I'm using D7.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
tcxbalage
  • 696
  • 1
  • 10
  • 30

1 Answers1

1

Source of problem found:

// does nothing, still grayed when losing focus
if (cdsSelected in State) then
  Sender.Canvas.Brush.Color := clHighlight;

// works fine
if (cdsSelected in State) then
  Sender.Canvas.Brush.Color := ColorToRGB(clHighlight);

For some reason the clHighlight color can not be used, probably there is some condition in the TTreeView code which is checking against this color and does something differently.

AmigoJack
  • 5,234
  • 1
  • 15
  • 31
tcxbalage
  • 696
  • 1
  • 10
  • 30
  • 1
    That's not specific to TTreeView. I would guess the handling is when the form loads properties, because you always need to do the conversion when setting them in code. – Garth Thornton Sep 16 '22 at 20:27