Select the TComboBox component in the Tool Palette, and drop it on the Form Designer. To find TComboBox, enter the first few characters ("Com") in the Search box of the Tool Palette:

After you drop the component, you can see the TComboBox component on the Form Designer. Right-click the TComboBox component and select Items Editor...:

To define items, click Add Item several times.

In the Structure View, select ListBoxItem1 (the first item in the list).

In the Object Inspector, edit the Text property for ListBoxItem1. In this example (the fifty states in the USA), enter "Alabama" as the first item in the list:

Edit other items as well, such as Alaska, Arizona, Arkansas, California, Colorado, and so forth.

Run the application on your chosen mobile target platform (iOS Simulator (for Object Pascal only), iOS Device, Android Emulator, or Android Device). After you tap TComboBox, the Picker control appears, and you can select an item.

Building a List of Items Using Code

To build a list of items using code, you should implement the onFormCreate event handler in the following way:

Object Pascal:

procedureTForm27.FormCreate(Sender:TObject);beginComboBox1.Items.Add('Alabama');ComboBox1.Items.Add('Alaska');ComboBox1.Items.Add('Arizona');ComboBox1.Items.Add('Arkansas');ComboBox1.Items.Add('California');// Other states can be listed hereComboBox1.Items.Add('Virginia');ComboBox1.Items.Add('Washington');ComboBox1.Items.Add('West Virginia');ComboBox1.Items.Add('Wisconsin');ComboBox1.Items.Add('Wyoming');end;

C++:

void__fastcallTForm27::FormCreate(TObject*Sender){ComboBox1->Items->Add("Alabama");ComboBox1->Items->Add("Alaska");ComboBox1->Items->Add("Arizona");ComboBox1->Items->Add("Arkansas");ComboBox1->Items->Add("California");// Other states can be listed hereComboBox1->Items->Add("Virginia");ComboBox1->Items->Add("Washington");ComboBox1->Items->Add("West Virginia");ComboBox1->Items->Add("Wisconsin");ComboBox1->Items->Add("Wyoming");}

Displaying a Specific Item

The currently selected item is specified by the ItemIndex property. ItemIndex is an integer value that is specified using a zero-based index (that is, the first item is zero).

To display the list with the fifth item selected ("California" in the following sample code), specify ItemIndex as follows:

Object Pascal:

procedureTForm27.FormCreate(Sender:TObject);beginComboBox1.Items.Add('Alabama');ComboBox1.Items.Add('Alaska');ComboBox1.Items.Add('Arizona');ComboBox1.Items.Add('Arkansas');ComboBox1.Items.Add('California');// Other states can be listed here// Index of 5th item is "4"ComboBox1.ItemIndex:=4;end;

C++:

void__fastcallTForm27::FormCreate(TObject*Sender){ComboBox1->Items->Add("Alabama");ComboBox1->Items->Add("Alaska");ComboBox1->Items->Add("Arizona");ComboBox1->Items->Add("Arkansas");ComboBox1->Items->Add("California");// Other states can be listed here// Index of 5th item is "4"ComboBox1->ItemIndex=4;}

If you do not know the index value, you can find the value by using the IndexOf method as follows:

Object Pascal:

procedureTForm27.FormCreate(Sender:TObject);beginComboBox1.Items.Add('Alabama');ComboBox1.Items.Add('Alaska');ComboBox1.Items.Add('Arizona');ComboBox1.Items.Add('Arkansas');ComboBox1.Items.Add('California');// Other states can be listed hereComboBox1.ItemIndex:=ComboBox1.Items.IndexOf('California');end;

C++:

void__fastcallTForm27::FormCreate(TObject*Sender){ComboBox1->Items->Add("Alabama");ComboBox1->Items->Add("Alaska");ComboBox1->Items->Add("Arizona");ComboBox1->Items->Add("Arkansas");ComboBox1->Items->Add("California");// Other states can be listed hereComboBox1->ItemIndex=ComboBox1->Items->IndexOf("California");}

Implementing an Event Handler for the User's Selection

After the user selects an item, the OnChange event is fired. To respond to the user's action, you can implement an event handler for the OnChange event.

Note: Before proceeding with this scenario, perform the following steps: