Lazarus

Programming => General => Topic started by: Jvan on August 04, 2020, 01:12:06 am

Title: Combobox: A value/key for each item?
Post by: Jvan 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.  
Title: Re: Combobox: A value/key for each item?
Post by: lainz on August 04, 2020, 01:31:40 am
You can use Items.Objects property to store objects for each item-
Title: Re: Combobox: A value/key for each item?
Post by: jamie 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..
Title: Re: Combobox: A value/key for each item?
Post by: gucao on August 04, 2020, 05:48:22 am
dblookupcombobox can do that.
Title: Re: Combobox: A value/key for each item?
Post by: jamie 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
TinyPortal © 2005-2018