Custom Combobox


This is my first post. I’m quite happy I managed to create a combobox with the Event “NotInList” that I used so much and loved when worked with VBA. I want to implement a feature that whenever the user types something that is not a row in the combobox, it is asked to add it in the database and on the combobox itself. It Works, but not the way I expected. The combobox fires the NotInList event but does not get it right all the times. I used the LostFocus event to fire a method that checks if the entry has a rowtag. If not, then it raises the NotInList event. I can’t understand why it does not work…

On the LostFocus event, there is a method with the code below:

[code]if me.ListIndex = -1 then
RaiseEvent NotInList
elseif me.RowTag(self.ListIndex) = nil then
RaiseEvent NotInList
end if


Any thoughts?

It would work a lot better in Keydown, upon Return or Tab.

Thanks, it did work. There is stil one glitch, though. The Autocomplete feature is on and I can see the text on the combobox, but when pressing tab or return (I have set the method that raises the NotInList event on the Keydown event as suggested) the event is still raised when the entry is already selected in the list but is not “blue” in the combobox field. Is there any way to work around it?

This is not clear. Let us see if I understand right :

  • The text field is not selected
  • User presses the lower arrows and selects an item in the list, then presses return or double clicks (which is not seen in keydown).

At this point the content of me.Text is one of the list items so you should test that. From your code, it seems the test is in NotInList itself.

It goes like this:

1 - User starts typing in the combobox (which has the Autocomplete feature turned on);
2 - When the appropriate entry shows up, user presses lower arrow and highlights it
3 - User then presses tab OR return (both keys produces the same outcome)

When proceeding like above, the NotInList event is fired. The odd thing is, it is not fired at all times these steps are followed…

If the user chooses to click on the entry and then hit tab OR return, it works fine.

I could test the me.Text value against an entry in the database. What do you think? Is it worthwhile? Isn’t it too much so as to impair performance?

Yes you should test. Do not worry about performance when interacting with the user, the user will always be much slower.