TComboBox (Delphi)

From RAD Studio XE2 Code Examples

Jump to: navigation, search

Language:

Versions:

Description

This is an example showing how to create a comboBox, add some choices to it, select a default value, and get the selected value.

Code

procedure TForm3.Button1Click(Sender: TObject);
begin
  MessageDlg('Selected text: ' + comb.Text, mtInformation,
            mbYesNo, 0);
end;
 
procedure TForm3.FormCreate(Sender: TObject);
begin
  //Initialize the combo box.
  comb := TComboBox.Create(Self);
  comb.Parent := Self;
 
  //Visual options
  comb.Align := alLeft;
  comb.DoubleBuffered := true;
  comb.AutoComplete := true;
 
  //Adding items to the combo box
  comb.AddItem('firstChoice', nil);
  comb.AddItem('secondChoice', nil);
  comb.AddItem('thirdChoice', nil);
 
  //Setting the default value
  comb.ItemIndex := 1;
end;

Uses

Personal tools
Previous Versions