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:

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  acol, arow: integer;
  P : TPoint;
  Re: TRect;
begin
  Re := StringGrid1.CellRect(acol, arow);
  P.X := Re.Bottom;
  P.Y := Re.Right;
  StringGrid1.Hint := getHint(acol, arow);
  Application.HintColor := clYellow;
  Application.ActivateHint(P);
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.

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.

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.

OldRow, OldCol : integer; // defined in TForm private

var
  P : TPoint;
  gc: TGridCoord;
begin
  gc := TStringGrid(Sender).MouseCoord(x, y) ;
  P.X := X;
  P.Y := Y;
  if  (gc.x <> OldCol) or (gc.y <> OldRow) then begin
   OldCol := gc.x;
   OldRow := gc.y;
   StringGrid1.Hint := 'Hint for '+inttostr(OldRow);
   Application.HintColor := clInfobk;
   Application.ActivateHint(P);
  end;

Thanks Tom, your coding solved my problem. Perhaps the above will get your tooltip off the caffeine jitters.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.