RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TComboExItems.AddItem Method

Adds a new item to the collection and initializes its properties.

Pascal
function AddItem(const Caption: string; const ImageIndex: Integer; const SelectedImageIndex: Integer; const OverlayImageIndex: Integer; const Indent: Integer; Data: TCustomData): TComboExItem;
C++
__fastcall TComboExItem AddItem(const AnsiString Caption, const int ImageIndex, const int SelectedImageIndex, const int OverlayImageIndex, const int Indent, TCustomData Data);

Call AddItem to add a new item to the collection. Add instantiates an object of the type that was specified when the TListControlItems instance was created. It then assigns the values of the Caption, ImageIndex, SelectedImageIndex, OverlayImageIndex, Indent, and Data parameters to the TComboExItem properties of the same names.  

C++ Examples: 

 

/*
This is a very simple example showing how to create a comboBoxEx, add
to it some items and images, indenting the items and getting the
selected value.
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//comboBoxEx initialization
combEx = new TComboBoxEx(this);
combEx->Parent = this;

//visual options
combEx->Align = TAlign::alLeft;
combEx->DoubleBuffered = true;

//adding image content
TCustomImageList* myImages = new TCustomImageList(16,16);
Graphics::TBitmap* image = new Graphics::TBitmap();

//for this examples the images are 50x50 pixels
image->LoadFromFile("..\\little_logo_16.bmp");
myImages->Add(image, NULL);
image->LoadFromFile("..\\littleB_16.bmp");
myImages->Add(image, NULL);
image->LoadFromFile("..\\little_sun_16.bmp");
myImages->Add(image, NULL);

combEx->Images = myImages;

//adding the items with the corresponding indexes to the images
//plus some indentations
combEx->ItemsEx->AddItem("firstChoiceEx", 0, 0, 0, 0, NULL);
combEx->ItemsEx->AddItem("secondChoiceEx", 1, 1, 1, 1, NULL);
combEx->ItemsEx->AddItem("thirdChoiceEx", 2, 2, 2, 2, NULL);

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

 

Delphi Examples: 

{
This is a very simple example showing how to create a comboBoxEx, add
to it some items and images, indenting the items and getting the
selected value.
}
procedure TForm3.Button1Click(Sender: TObject);
begin
  MessageDlg('Selected text: ' + combEx.Text,
             mtInformation, mbYesNo, 0);

end;

procedure TForm3.FormCreate(Sender: TObject);
var
  myImages : TImageList;
  image : TBitmap;
begin
  //comboBoxEx initialization
  combEx := TComboBoxEx.Create(Self);
  combEx.Parent := Self;

  //visual options
  combEx.Align := alLeft;
  combEx.DoubleBuffered := true;

  //initializing the TBitmap
  image := TBitmap.Create();

  //adding image content
  myImages := TImageList.CreateSize(64, 64);
  image.LoadFromFile('little_logo_64.bmp');
  myImages.Add(image,nil);
  image.LoadFromFile('littleB_64.bmp');
  myImages.Add(image,nil);
  image.LoadFromFile('little_sun_64.bmp');
  myImages.Add(image,nil);

  combEx.Images := myImages;

  //adding the items with the corresponding indexes to the images
  //plus some indentations

  combEx.ItemsEx.AddItem('firstChoiceEx', 0, 0, 0, 0, nil);
  combEx.ItemsEx.AddItem('secondChoiceEx', 1, 1, 1, 1, nil);
  combEx.ItemsEx.AddItem('thirdChoiceEx', 2, 2, 2, 2, nil);
  ComboBoxEx1.ItemsEx.AddItem('firstChoiceEx', 0, 0, 0, 0, nil);
  ComboBoxEx1.ItemsEx.AddItem('secondChoiceEx', 1, 1, 1, 1, nil);
  ComboBoxEx1.ItemsEx.AddItem('thirdChoiceEx', 2, 2, 2, 2, nil);

   //setting the default value
  combEx.ItemIndex := 1;
  ComboBoxEx1.ItemIndex := 0;

end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!