Search code examples
delphidelphi-2010delphi-xe7

Altering ITEMINDEX of TComboBox does not trigger it's OnChange event


When programmatically changing the value of ItemIndex of a TComboBox component in Delphi, one would expect for the corresponding OnChange event to get triggered.

Afterall, the visible value of the ComboBox get's changed as a result. Strangely it does not. Same behavior in Delphi6, Delphi 2010 and Delphi XE7.

Is there any reason behind this behavior or it's just a pending bug?


Solution

  • From documentation:

    Occurs when the user changes the text displayed in the edit region.

    Write an OnChange event handler to take specific action immediately after the user edits the text in the edit region or selects an item from the list. The Text property gives the new value in the edit region.

    Note: OnChange only occurs in response to user actions. Changing the Text property programmatically does not trigger an OnChange event.

    Since there is no editing done, this means that programmatically changing the ItemIndex does not trigger the OnChange event.