Recent

Author Topic: (Solved) DBGrid and dgCellHints property  (Read 649 times)

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
(Solved) DBGrid and dgCellHints property
« on: October 06, 2022, 12:46:56 am »
Hi folks

I was surprised to find that dgCellHints property doesn't display tooltips. I made a test project with the following code

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: PtrInt = 0;
  4. begin
  5.   with MemDataset1 do
  6.   begin
  7.     FieldDefs.Add('ID',ftInteger);
  8.     FieldDefs.Add('Name',ftString,100);
  9.     CreateTable;
  10.     Active:= True;
  11.  
  12.     for i:= 3 to 20 do
  13.     begin
  14.       Append;
  15.       FieldByName('ID').AsInteger:= i;
  16.  
  17.       case (i mod 3) of
  18.         0: FieldByName('Name').AsString:= Format('item_%d timestamp %s',
  19.                                   [i,FormatDateTime('mm/dd/yyyy_hh:nn:ss.zzz',Now)]);
  20.         1: FieldByName('Name').AsString:= Format('item_%d',[i]);
  21.         else
  22.           FieldByName('Name').AsString:= Format('timestamp %s',[FormatDateTime('mm/dd/yyyy_hh:nn:ss.zzz',Now)]);
  23.       end;
  24.  
  25.     end;
  26.  
  27.     with DBGrid1 do
  28.     begin
  29.       Columns.Add;
  30.       Columns.Add;
  31.       Columns.Items[0].Width:= 30;
  32.       Columns.Items[0].FieldName:= 'ID';
  33.       Columns.Items[1].Width:= 200;
  34.       Columns.Items[1].FieldName:= 'Name';
  35.  
  36.       ShowHint:= True;
  37.       CellHintPriority:= chpTruncOnly;
  38.       Options:= Options
  39.                 + [dgCellEllipsis]
  40.                 + [dgCellHints]
  41.                 + [dgRowSelect]
  42.                 ;
  43.     end;
  44.   end;
  45. end;
                                   

Can I messed up something in the Dbgrid parameters?

movies
https://i.imgur.com/vkABoqq.mp4
« Last Edit: October 06, 2022, 12:46:44 pm by zoltanleo »
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: DBGrid and dgCellHints property
« Reply #1 on: October 06, 2022, 01:15:24 am »
I didn't look at your code but, did you implement the "OnGetCellHint" ?

It looks like you need to supply it with the hint..
The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: DBGrid and dgCellHints property
« Reply #2 on: October 06, 2022, 01:38:44 am »
Hi jamie

Hmmmm.  I naively thought that the grid would display tooltips on its own without additional coding.  This is how the virtualtreeview component does, for example  :o
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: DBGrid and dgCellHints property
« Reply #3 on: October 06, 2022, 11:37:38 am »
There are two types of cell-specific hints:
  • "normal" hints which can display any cell-related text. The text is defined in the OnGetCellHint event. They are activated by adding goCellHints (gdCellHints in case of the DBGrid) to the grid's Options.
  • "truncated cell hints", i.e. the hints for cell in which the text has been truncated because the cell with is too small (that's what you need). They are activated by adding goTruncCellHints (dgTruncCellHints in case of the DBGrid) to the grid's Options.
So, the first solution is to replace the dgCellHints by dbTruncCellHints when you set up the grid's Options.

Both kinds of cell hints can be combined, and even the normal Hint of the grid (DBGrid.Hint) can be included. What finally is shown is determined by the CellHintPriority property:
  • chpAll: display all three hint texts
  • chpAllNoDefault: display "normal" cell hints and "truncated cell hints", but not DBGrid.Hint
  • chpTruncOnly: display only the truncated cell hints.
Therefore the second solution would be to replace the chpTruncOnly by chpAllNoDefault (since there is no OnGetCellHint handler the normal cell hint would not be shown).

Select one of the two solutions.

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
Re: DBGrid and dgCellHints property
« Reply #4 on: October 06, 2022, 12:39:51 pm »
Hi Werner

Thank you very much for the clarifications. I didn't finish my experiments a bit. Otherwise, my issue would have resolved itself.   :D

I have corrected my code as follows:

Code: Pascal  [Select][+][-]
  1. with DBGrid1 do
  2. begin
  3.   CellHintPriority:= chpTruncOnly;
  4.   Options:= Options
  5.                 + [dgCellEllipsis]
  6.                 + [dgCellHints]
  7.                 + [dgRowSelect]
  8.                 + [dgTruncCellHints]
  9.                 ;
  10. end;

Once again, I would like to thank all you for participating in the discussion.
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

 

TinyPortal © 2005-2018