I'm having an issue with the combo box. I have an event handler for OnClick
which refreshes data based on what item was selected. The problem is when this scenario occurs:
OnClick
eventOnClick
was already calledOnClick
isn't called againSo when you open a combo box, and type a few letters on the keyboard to find the item in the drop-down list, OnClick
is fired which refreshes my screen. But when you click somewhere outside the combo box (thus taking the focus away from it), the combo box changes back to whatever value was previously selected, instead of what I had typed. And at the same time, the OnClick
event isn't fired, so the combo box shows the incorrect value compared to what I had loaded on the screen.
How do I make the combo box stay on the selected item in this scenario of typing the item on the keyboard?
In my code, I deal with this using the OnCloseUp
event. Well, in fact I'm using a sub-classed combo for my drop-down lists and they override both the Change
and CloseUp
methods:
procedure TMyDropDownList.Change;
begin
RespondToChange;
inherited;
end;
procedure TMyDropDownList.CloseUp;
begin
RespondToChange;
inherited;
end;
The RespondToChange
method reacts to the new ItemIndex
value. If it is expensive to react to every single change whilst the combo is dropped down, then you might consider omitting the call to RespondToChange
from the Change
method.