Recent

Author Topic: [SOLVED] How to replace DBGrid cell display text?  (Read 451 times)

Vodnik

  • Full Member
  • ***
  • Posts: 210
[SOLVED] How to replace DBGrid cell display text?
« on: November 20, 2023, 06:49:55 pm »
My application uses CSVDataset and DBgrid. I would like to display text instead of integer values in some DBGrid columns, e.g. for the field 'calldirection': 'incoming' instead of 1, 'outgoing' instead of 2 and 'internal' instead of 3.

When dealing with SQL database, solution is to use GetText event handler in TSQLQuery.
How to obtain the same result with in-memory database, when TSQLQuery is not used?
 
« Last Edit: November 20, 2023, 08:16:39 pm by Vodnik »

wp

  • Hero Member
  • *****
  • Posts: 11765
Re: How to replace DBGrid cell display text?
« Reply #1 on: November 20, 2023, 07:43:50 pm »
In the same way: Assign a OnGetText handler to the field to be converted. See attachment.

korba812

  • Sr. Member
  • ****
  • Posts: 389
Re: How to replace DBGrid cell display text?
« Reply #2 on: November 20, 2023, 07:45:25 pm »
You can still use GetText event, just you have to assign it at runtime.
Eg:
Code: Pascal  [Select][+][-]
  1.   CSVDataset1.Open;
  2.   CSVDataset1.Fields[1 {field index}].OnGetText := @MyGetTextHandler;
  3.  

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: How to replace DBGrid cell display text? [Solved]
« Reply #3 on: November 20, 2023, 08:16:02 pm »
Great thanks, @wp and @korba812!

 

TinyPortal © 2005-2018