RAD Studio VCL Reference
|
Adds an item to the drop-down list of items.
procedure AddItem(Item: String; AObject: TObject); override;
virtual __fastcall AddItem(AnsiString Item, TObject * AObject);
Call AddItem to add a string, with an associated object, to the drop-down list.
Item is the string to add to the drop-down list.
AObject is an object associated with that string. It can be accessed using the Objects property of the TStrings object that implements the Items property.
C++ Examples:
/* This is a very simple example showing how to create a comboBox, add to it some choices, selecting a default value and getting the selected value. */ void __fastcall TForm1::FormCreate(TObject *Sender) { //comboBox initialize 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); }
Delphi Examples:
{ This is a very simple example showing how to create a comboBox, add to it some choices, selecting a default value and getting the selected value. } 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;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|