Search code examples
delphitreeviewhint

Delphi: Custom hints for Tree View


Is there a fast way to create 5 custom hints for 5 SubItems of Item of Tree View?

I have TreeView, 1 Item and 5 SubItems. I need a special hint for each SubItem (for first one - "F1", second one -"F2" and so on).

I can not apply this to my purpose: http://delphi.about.com/od/vclusing/a/treenode_hint.htm?


Solution

  • It sounds like you just want the OnHint event:

    procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
    begin
      Hint := Node.Text;
    end;
    

    Sometimes this method can be a bit crude and offer up a Node that you aren't obviously hovering over. If you want more control you can use GetNodeAt and GetHitTestInfoAt:

    procedure TMyForm.TreeView1Hint(Sender: TObject; const Node: TTreeNode; var Hint: string);
    var
      P: TPoint;
      MyNode: TTreeNode;
      HitTestInfo: THitTests;
    begin
      P := TreeView1.ScreenToClient(Mouse.CursorPos);
      MyNode := TreeView1.GetNodeAt(P.X, P.Y);
      HitTestInfo := TreeView1.GetHitTestInfoAt(P.X, P.Y) ;
      if htOnItem in HitTestInfo then begin
        Hint := MyNode.Text;
      end else begin
        Hint := '';
      end;
    end;
    

    The definition of THitTests is as follows:

    type
      THitTest = (htAbove, htBelow, htNowhere, htOnItem, htOnButton, htOnIcon,
        htOnIndent, htOnLabel, htOnRight, htOnStateIcon, htToLeft, htToRight);
      THitTests = set of THitTest;
    

    As you can see this gives you a lot of fine grained control over when and what you show as a hint.