ComboBox with key / value pairs

Hello, is there a way to add key/value pairs to a TWebCombobox? It should in html look like:

<select>
  <option value="1">male</option>
  <option value="2">female</option>
</select>

Regards
Harald

You could use the TWebLookupComboBox for this.

This is how I make it with bootstrap:

in HTML

Country

In dfm use TWebComboBox and I set the next properties:
ElementClassName = form-select
ElementID = ComboBoxCD_COUNTRY

After in the .pas you can assign the values like this:

ComboBoxCD_COUNTRY.Items.Add('United States=USA');
ComboBoxCD_COUNTRY.Items.Add('Canada=CAN');
ComboBoxCD_COUNTRY.Items.Add('Australia=AUS');
ComboBoxCD_COUNTRY.Items.Add('Brazil=BRA');

And you can set the value selected using ComboBoxCD_COUNTRY.ItemIndex:
ComboBoxCD_COUNTRY.ItemIndex := 2;

1 Like