Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a TreeView control without selecting all nodes?

I don't know if this is a bug or something, but if I try to disable a TTreeView control, all the nodes become selected (grayed out)... Can anything be done to just disable the input for this control without changing the selection ? Of course, the node are not really selected, they are just visually selected, but this is annoying.

enter image description here

like image 594
Marus Gradinaru Avatar asked Dec 06 '19 16:12

Marus Gradinaru


1 Answers

That's how the disabled control looks like when no theme is applied. You can modify it with little intervention to item drawing:

procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
  var PaintImages, DefaultDraw: Boolean);
begin
  if (not TreeView1.Enabled) and
      (GetWindowTheme(TreeView1.Handle) = 0) and (Stage = cdPrePaint) then begin
    TreeView1.Canvas.Brush.Color := clWindow; // or TreeView1.Color
    TreeView1.Canvas.Font.Color := clGrayText;
  end;
end;

Unfortunately the State never includes 'cdsDisabled' or 'cdsGrayed' (which I didn't investigate), so the code tests if the treeview is enabled or not.

like image 174
Sertac Akyuz Avatar answered Oct 29 '22 09:10

Sertac Akyuz