944,221 Members | Top Members by Rank

Ad:
Jun 20th, 2009
0

TStringGrid per-cell tooltips?

Expand Post »
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:

delphi Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
TomRandall is offline Offline
9 posts
since Nov 2008
Jun 20th, 2009
0

Re: TStringGrid per-cell tooltips?

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mediastar is offline Offline
8 posts
since Jun 2009
Oct 5th, 2009
0

Re: TStringGrid per-cell tooltips?

Click to Expand / Collapse  Quote originally posted by TomRandall ...
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.
delphi Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
bob on whidbey is offline Offline
32 posts
since Oct 2007
Nov 10th, 2009
0
Re: TStringGrid per-cell tooltips?
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!
Reputation Points: 12
Solved Threads: 5
Junior Poster in Training
BitFarmer is offline Offline
51 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Better way to do this Robot?
Next Thread in Pascal and Delphi Forum Timeline: how do i get shellexecute to work?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC