1
votes

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?

2
Can you provide some more details? The code that you tried would be good.Miki
Please be more specific about what it is about that code that doesn't work for you. We aren't keen to guess all day.Rob Kennedy

2 Answers

3
votes

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.

1
votes

I would set the hint of the component in response to OnMouseMove (or that other event that gives you mouse coordinates, from which you can get the item the mouse is over - I might have mistaken the name and at the moment I have no Delphi with me).