Jump to content

Populate dinamically a Combobox


marcos.digirotas

Recommended Posts

I have a Combobox which needs to be repopulated dinamically, that is, the user type 3 characters in the ComboBox and press the return key. In this moment a query is executed and the Combobox needs to be populated with the items resulted by that query. The problem that I found is that the ComboBox.Items.Clear doesn't have the expected effect.

Here is a simple example:

  • Add a TUniComboBox
  • On the OnKeyDown method, add the code:

  if Key=VK_RETURN then
  begin
    UniComboBox1.Items.Clear;

    UniComboBox1.Items.Add('RIO DE JANEIRO');
    UniComboBox1.Items.Add('RIO GRANDE DO SUL');
    UniComboBox1.Items.Add('RIO GRANDE DO NORTE');
  end;

  • Run the program
  • Inside the ComboBox, type "RIO" and press the return key: it will appear 3 items at the  ComboBox
  • Edit the typed text to "RIOS" and press the return key again

In this moment I expected that the Combobox was cleared and populated with the 3 options, but the result obtained is that the ComboBox has 6 items, as if the "UniComboBox1.Items.Clear" instruction had been ignored.

Thanks in advance!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...