TComboBoxEx (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to create a comboBoxEx, add some items and images to it, indent the items, and get the selected value.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
//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 example, 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(L"firstચ૨૪ChoiceEx", 0, 0, 0, 0, NULL);
combEx->ItemsEx->AddItem(L"secondચ૨૪ChoiceEx", 1, 1, 1, 1, NULL);
combEx->ItemsEx->AddItem(L"thirdચ૨૪ChoiceEx", 2, 2, 2, 2, NULL);

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

Uses