How to remove a Tlistbox selection

Asked

Viewed 1,103 times

1

I’m creating a component to serve as a refinement for research, 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 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, Tlistbox is updated with only the values that match the Tedit value. You can also select a Tlistbox value so that Tedit is filled with this value.

My doubt (and problem) is in the exit of Tlistbox. When the focus leaves Tlistbox, none of the values should remain selected, where the user can also return to Tedit (including 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 Tlistbox items are unchecked, only at some point the first item is selected again, and I don’t know why or how to fix or circumvent it. If I use the mouse to exit Tlistbox and go to Tedit the list has the values unchecked and works correctly, without marking any value again.

1 answer

1

Enough at the event OnExit() from your Listbox you make the following code:

ListBox1.ClearSelection;
  • Thank you so much for the answer. I’ve tried this solution and it didn’t work. What’s strange is that when I leave by clicking with the mouse, it goes through the event OnExit() and when I preview the form there is no item selected. When I exit with the arrow up, going to the same Tedit, it goes through the event OnExit(), and actually the items are unchecked. But when I view the form the first item is selected, visually and in the properties.

  • Strange, because I tested it here and it worked, unless there are extra checks in your code. Debug and check why this is happening.

  • Even facing up by the arrow? I have an event an event OnKeyDown() which checks when the up arrow goes,.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.