Home > Software engineering >  Delphi FMX, change TComboBox images at runtime
Delphi FMX, change TComboBox images at runtime

Time:01-17

If I programmatically change TComboBox.Images to a new TImageList, only the selected icon in the TComboBox changes, all other icons in the TComboBox (drop-down list) remain the same.

I have two TImageLists, one with color icons and one with black and white icons and I want to change the black and white icons to colored icons and vice versa.

procedure TfrmMain.Button1Click(Sender: TObject);
begin
  if ComboBox1.Images = ImageList1 then
    ComboBox1.Images := ImageList2
  else
    ComboBox1.Images := ImageList1;
end;

enter image description here

CodePudding user response:

As pointed in the question comments this is indeed a bug in Delphi as the internal drop down list is not refreshed when changing the Images property after showing the popup at least one time. This can be corrected by making a small change in the FMX.ListBox.pas source file at TCustomComboBox.SetImages procedure (tested on Delphi 11):

procedure TCustomComboBox.SetImages(const Value: TCustomImageList);
begin
  FImageLink.Images := Value;
  FItemsChanged := True;        // <- Add this
end;
  •  Tags:  
  • Related