Recent

Author Topic: TDBGrid.OnGetCellHint determine cell  (Read 1733 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 361
TDBGrid.OnGetCellHint determine cell
« on: August 19, 2025, 09:17:43 pm »
I have a TDBGrid and I want to show a specific hint for different rows. How to determine for which row hint was called?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Bart

  • Hero Member
  • *****
  • Posts: 5612
    • Bart en Mariska's Webstek
Re: TDBGrid.OnGetCellHint determine cell
« Reply #1 on: August 19, 2025, 10:18:41 pm »
OK, the signature of OnGetCellHit for DBGrid is not the same as for TStringGrid.
Maybe you can use MouseToCell() to determine the cell?

Bart

wp

  • Hero Member
  • *****
  • Posts: 13210
Re: TDBGrid.OnGetCellHint determine cell
« Reply #2 on: August 19, 2025, 10:56:40 pm »
When you want to display an individual hint for specific cells you must store these hints somewhere. I think the most natural way for a database application is to provide a separate field for the hint text. In this case you can simply read the field value and assign it to the Text output parameter of the OnGetCellHint event.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1GetCellHint(Sender: TObject; Column: TColumn;
  2.   var AText: String);
  3. begin
  4.   case Column.Field.FieldName of
  5.     'ID'   : AText := MemDataset1.FieldByName('Hint_ID').AsString;
  6.     'Name' : AText := MemDataset1.FieldByName('Hint_Name').AsString;
  7.   end;
  8. end;

See attached project.

LemonParty

  • Sr. Member
  • ****
  • Posts: 361
Re: TDBGrid.OnGetCellHint determine cell
« Reply #3 on: August 20, 2025, 04:51:28 pm »
Thank you, wp. It works.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018