8

I'm using a TComboBox component with the style property set to csOwnerDrawFixed, I implement the OnDrawItem And everything works fine, Now I want which the combobox to behave like when had the csDropDown style (with the csOwnerDrawFixed style behaves like the csDropDownList style) , I mean with a inner editor. is this possible?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Salvador
  • 16,132
  • 33
  • 143
  • 245

2 Answers2

8

Delphi's TComboBox wrapper doesn't support an owner draw editable style, but the underlying Windows control does, and it's easy to enable it.

Create a new descendant class like so:

TComboBox = class(StdCtrls.TComboBox)
public
  procedure CreateParams(var Params: TCreateParams); override;
end;

procedure TComboBox.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if Assigned(OnDrawItem) then
    Params.Style := Params.Style or CBS_OWNERDRAWFIXED
end;

Set the Style to csDropDown and assign OnDrawItem like you're already doing.

Zoë Peterson
  • 13,094
  • 2
  • 44
  • 64
0

None of the OwnerDraw styles support the presence of an edit box in the TComboBox. You will have to use a separate TEdit instead.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770