TStringGrid per-cell tooltips?

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 9
Reputation: TomRandall is an unknown quantity at this point 
Solved Threads: 0
TomRandall TomRandall is offline Offline
Newbie Poster

TStringGrid per-cell tooltips?

 
0
  #1
Jun 20th, 2009
Hi All,

I'm using a TStringGrid (has to be Delphi 7, and no 3rd party components) I've customised it to allow per-cell colouring/fonts/borders/validation etc, by using a custom onDrawCell method.

I really would like to add per-cell tooltips too, but I've been unsuccessful so far. I've modified something I found:

  1. procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3. acol, arow: integer;
  4. P : TPoint;
  5. Re: TRect;
  6. begin
  7. Re := StringGrid1.CellRect(acol, arow);
  8. P.X := Re.Bottom;
  9. P.Y := Re.Right;
  10. StringGrid1.Hint := getHint(acol, arow);
  11. Application.HintColor := clYellow;
  12. Application.ActivateHint(P);
  13. end;

Which kind of works, but it tries to display the tooltip every px moved, making it very laggy, and it displays it without having to "pause" for a while, like you do with regular tooltips.

If anyone knows of an easier/proper way to implement this it would be much appreciated.

Thanks in advance.
Last edited by TomRandall; Jun 20th, 2009 at 8:06 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: mediastar is an unknown quantity at this point 
Solved Threads: 0
mediastar mediastar is offline Offline
Newbie Poster

Re: TStringGrid per-cell tooltips?

 
0
  #2
Jun 20th, 2009
TomRandall,

A simple way is to use the OnHint event of the Application global variable. You can easily fulfil your tasks in an event handler. The effect is much better than MouseMove event.

A more general way is to build a separate thread to monitor mouse movement. You can manipulate everything in this way but it is more resource-consuming.

I think your advanced StringGrid is a very good idea. Wish you success.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 20
Reputation: bob on whidbey is an unknown quantity at this point 
Solved Threads: 0
bob on whidbey bob on whidbey is offline Offline
Newbie Poster

Re: TStringGrid per-cell tooltips?

 
0
  #3
Oct 5th, 2009
Originally Posted by TomRandall View Post
Hi All,

... but it tries to display the tooltip every px moved, making it very laggy, and it displays it without having to "pause" for a while, like you do with regular tooltips.

If anyone knows of an easier/proper way to implement this it would be much appreciated.

Thanks in advance.
  1.  
  2. OldRow, OldCol : integer; // defined in TForm private
  3.  
  4. var
  5. P : TPoint;
  6. gc: TGridCoord;
  7. begin
  8. gc := TStringGrid(Sender).MouseCoord(x, y) ;
  9. P.X := X;
  10. P.Y := Y;
  11. if (gc.x <> OldCol) or (gc.y <> OldRow) then begin
  12. OldCol := gc.x;
  13. OldRow := gc.y;
  14. StringGrid1.Hint := 'Hint for '+inttostr(OldRow);
  15. Application.HintColor := clInfobk;
  16. Application.ActivateHint(P);
  17. end;

Thanks Tom, your coding solved my problem. Perhaps the above will get your tooltip off the caffeine jitters.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 40
Reputation: BitFarmer is an unknown quantity at this point 
Solved Threads: 4
BitFarmer BitFarmer is offline Offline
Light Poster
 
0
  #4
Nov 10th, 2009
Why do you need to activate the hint (Application.ActivateHint(P)) by code?

If grid.showhint is true, just changing the hint text should be ok... have you tried it without this line?

Anyhow, the application.onhint event is tricky, for a component that can have several instances on one app, using this event is tricky, as only one event handler can exists, and you need one per grid and manage it when one is freed... dificult one!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC