How to unselect a TListBox

1

I'm creating a component to serve as search refinement, offering suggestions. This component has a TEdit where you can enter what you want to search, a list where possible values for suggestion are stored and a TListBox to present the suggestions.

I have a class that inherits from the TWinControl class, which in turn has 2 subcomponents: (i) a TEdit; (ii) and a TListBox. When editing TEdit the TListBox is updated showing only the values that match the TEdit value. You can also select a value from the TListBox so that TEdit is populated with this value.

My question (and problem) is in the output of the TListBox. When the focus exits the TListBox, none of the values should remain selected, where the user can also go back to TEdit (even with the up arrow). In the output of this component I am using ItemIndex := -1; . This works, but when I use the up key, the focus goes to TEdit, and the items in the TListBox are unmarked, only that at some point the first item is selected again, and I do not know why or how to fix or circumvent it. If I use the mouse to exit the TListBox and go to TEdit the list has the values cleared and works correctly without marking any values again.

    
asked by anonymous 15.09.2015 / 13:37

1 answer

1

Just in the event OnExit() of your ListBox you make the following code:

ListBox1.ClearSelection;
    
15.09.2015 / 13:44