Short Version
How do i make OnChange event fire when the text in the combobox changes?
Long version
I am using IAutoComplete2 to add an "auto-suggest" (i.e. drop-down) list to a Combobox.
As the user selects different options in the suggestion list, the text in the combobox changes, but unfortunately no OnChange event fires:
When attaching the AutoComplete to a naked TEdit the OnChange event is fired.
function SHAutoCompleteComboShell(AComboBox: TComboBox): IAutoComplete2;
var
cbi: TComboBoxInfo;
hEdit: HWND; //A handle to the edit box.
strings: IEnumString;
ac: IAutoComplete2;
const
Default_TComboBoxInfo: TComboBoxInfo = ();
begin
//Example public domain pseudocode on how to autocomplete a combobox.
Result := nil;
if AComboBox = nil then
Exit;
//Get the EDIT control inside the Combobox
cbi := Default_TComboBoxInfo;
cbi.cbSize := sizeof(TComboBoxInfo);
if not GetComboBoxInfo(AComboBox.Handle, {var}cbi) then
Exit;
hEdit := cbi.hwndItem; //A handle to the edit box.
if hEdit = 0 then
Exit;
//Suggest strings from the shell namespace
strings := CreateComObject(CLSID_ACListISF) as IEnumString;
ac:= CreateComObject(CLSID_IAutoComplete) as IAutoComplete2;
ac.Init(hEdit, strings, nil, nil);
ac.SetOptions(ACO_AUTOSUGGEST);
Result := ac;
end;
Even as the user does the final Enter to select an option, the TComboBox's OnChange still never fires.
I assume the Windows Edit control is sending an EN_CHANGE notification message that its text has changed; but the TComboBox isn't caring.
The TComboBox is, of course, in csDropDown
style (otherwise why would i be asking the question).
Tried in Delphi 5, Delphi XE6
TComboBoxEx
(that is, aComboBoxEx
control -- get the edit handle using CBEM_GETEDITCONTROL). Are you willing to use such a control instead? – Andreas Rejbrand Jan 26 at 20:55