ComboBox (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to create a combo box, add some choices to it, select a default value, and get the selected value.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
//ComboBox initialization
comb = new TComboBox(this);
comb->Parent = this;

//Visual options
comb->Align = TAlign::alLeft;
comb->DoubleBuffered = true;
comb->AutoComplete = true;

//Adding items to the combo box
comb->AddItem("firstChoice",NULL);
comb->AddItem("secondChoice",NULL);
comb->AddItem("thirdChoice",NULL);

//Setting the default value
comb->ItemIndex = 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MessageDlg("Selected text: " + comb->Text,
			mtInformation, TMsgDlgButtons() << mbOK, 0);
}

Uses