Recent

Author Topic: Combobox: A value/key for each item?  (Read 376 times)

Jvan

  • Full Member
  • ***
  • Posts: 108
Combobox: A value/key for each item?
« on: August 04, 2020, 01:12:06 am »
I want to show the user a combobox whose items have hiden values. For instance, the user will see these options: "Manzanas, Peras, Platanos"; but each will have a hiden value or key: "M1, P1, P2". There is a property for that or I must only use an array:

Code: Pascal  [Select][+][-]
  1.    myValue := MyKeyArray[ComboBox1.ItemIndex];
  2.  

lainz

  • Hero Member
  • *****
  • Posts: 3695
  • Leandro Diaz
Re: Combobox: A value/key for each item?
« Reply #1 on: August 04, 2020, 01:31:40 am »
You can use Items.Objects property to store objects for each item-

jamie

  • Hero Member
  • *****
  • Posts: 3507
Re: Combobox: A value/key for each item?
« Reply #2 on: August 04, 2020, 03:02:02 am »
Use a Tcombobox in OwnerDraw mode..

Populate the list with the Visible Text = HiddenText;

When painting the list only paint the TEXT for each cell that gets called for a paint job.

For example of one line

 Manzanas=M1

And using the items you can look at the KEYS and VALUES array
so when painting each item you paint only the KEYS and when the user select the item you can use the VALUES to obtain the M1 for example..
The only true wisdom is knowing you know nothing

gucao

  • Newbie
  • Posts: 2
Re: Combobox: A value/key for each item?
« Reply #3 on: August 04, 2020, 05:48:22 am »
dblookupcombobox can do that.

jamie

  • Hero Member
  • *****
  • Posts: 3507
Re: Combobox: A value/key for each item?
« Reply #4 on: August 04, 2020, 10:49:14 pm »
Use a Tcombobox in OwnerDraw mode..

Populate the list with the Visible Text = HiddenText;

When painting the list only paint the TEXT for each cell that gets called for a paint job.

For example of one line

 Manzanas=M1

And using the items you can look at the KEYS and VALUES array
so when painting each item you paint only the KEYS and when the user select the item you can use the VALUES to obtain the M1 for example..

I wanted to make a correction, its "NAMES" not "KEYS" that are the items you use to paint the text to the cell area of the drop down when the OnDraw…. Event triggers...

 If you need an example of this just ask
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018