Default selection color when TreeView is not focused

345 Views Asked by At

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.

1

There are 1 best solutions below

1
tcxbalage On

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.