TComboBoxEx (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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

Code

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
  //Applying 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;

Uses