Recent

Author Topic: Create a key-value pair picklist for a combobox in a DBgrid  (Read 447 times)

Hansvb

  • Sr. Member
  • ****
  • Posts: 469
Create a key-value pair picklist for a combobox in a DBgrid
« on: January 07, 2023, 07:21:49 pm »
I have 2 tables. For example, the main table has the following columns:
COL_A, COL_B, COL_C, COL_DOM_ID. Table 2 is the domain list and consists of ID, NAME. DOM_ID in table A is ID of table B.

Now I want to show table A in a DBgrid and show the DOM_ID column as combobox. The drop-down list must then contain the unique NAMES of table B and the ID (not the NAME), must then be saved when saving. So I'm looking for a way to create a key-value picklist for the combobox in the dbgrid. Is that possible? In the grid reference example, the picklist only consists of a tstringlist.

With this is seems to work. But there must be a better solution. :
Quote
https://www.thoughtco.com/place-dblookupcombobox-into-dbgrid-4077834
« Last Edit: January 07, 2023, 07:44:26 pm by Hansvb »

korba812

  • Sr. Member
  • ****
  • Posts: 336
Re: Create a key-value pair picklist for a combobox in a DBgrid
« Reply #1 on: January 08, 2023, 02:20:42 am »
You can get this using lookup fields:
https://www.delphipower.xyz/guide_8/lookup_fields.html
https://www.tek-tips.com/faqs.cfm?fid=1213
http://etutorials.org/Programming/mastering+delphi+7/Part+III+Delphi+Database-Oriented+Architectures/Chapter+13+Delphi+s+Database+Architecture/The+Fields+of+a+Dataset/

Edit:
After reading your post more carefully, the lookup fields will not be enough as they only allow you to select from the list but not to edit/add a new record in the lookup list directly from DBGrid.
« Last Edit: January 08, 2023, 02:33:41 am by korba812 »

Hansvb

  • Sr. Member
  • ****
  • Posts: 469
Re: Create a key-value pair picklist for a combobox in a DBgrid
« Reply #2 on: January 14, 2023, 03:43:17 pm »
i am looking for an DBgrid with DBLookupCombobox example.
I found this:
Quote
https://www.thoughtco.com/place-dblookupcombobox-into-dbgrid-4077834
and almost the same example:
http://www.delphicorner.f9.co.uk/articles/comps10.htm


it works for the most part. Sendmessage() does not work: 

Code: Pascal  [Select][+][-]
  1. SendMessage(DBLookupComboBox1.Handle, WM_Char, word(Key), 0);

lazarus does not recognize WM_Char. furthermore, in the cell with the DBlookupbox, not the value but the ID is shown.
So i must do something wrong and a good example would help.


 

TinyPortal © 2005-2018