Changing default behaviour for TCombobox

305 Views Asked by At

I have a project with multiple forms that use TCombobox and i would like to remove the default behavior when a focused combobox receives a Return stroke:

In the Keydown of TCustomCombobox:

vkF4, vkReturn:
    DropDown;

Q: How could i remove the functionality for all my forms?

Creating a new custom control that overrides this would mean to much work to recreate all the comboboxes.

A: Make an "imposter" subclass :

Found a Duplicate question : Delphi subclass visual component and use it

I put this code in a unit, and put that unit in the interface/uses of my forms.

TCombobox = class(FMX.ListBox.TComboBox)
  protected
    procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);override;
  end;

procedure TCombobox.KeyDown(var Key: Word; var KeyChar: System.WideChar;
  Shift: TShiftState);
begin
  if key=vkReturn then exit;
  inherited;
end;
0

There are 0 best solutions below