Help stop a listbox from stealing focus!

NJDubois

Well-known member
Joined
May 15, 2008
Messages
84
Programming Experience
Beginner
I have a list of textboxs that are binded to a database.

When a user starts to type in one of these textboxs I draw a listbox right under that textbox that shows a list of other items in the field that start with the same keys.

IE, the user types in "Ni" and the list box will have "Nick" and "Nicholas" and so on...

That all works great but when I hit tab I want the next textbox to get focus and the listbox to hide.

If I just wait for the textbox to lose focus you can't do anything with the listbox because DOH the textbox just lost focus and the lsitbox hides.

This has led me in a circle of I'll try this and I'll try that for a while now.

I have listbox.tabstop set to false.

I've tried to manually set focus to the next textbox but the problem is that the listbox gets the focus that instant and all the gotfocus lostfocus code for the textbox is ignored.

I can't out right ignore the listbox getting focus.

What is the recommendation of the vbdotnotforums community?
Thanks for any advice!
Nick
 
Auto Complete is EXACTLY what I was looking for. Many thanks!

How do I update the autocompletelist source after the control has been created?

dim a_textbox as new textbox
a_textbox.AutoCompleteCustomSource = a_list_of_strings


And then later, maybe after a record is added to the database
a_textbox.AutoCompleteCustomSource = a_list_of_strings_updated

All this does is cause the autocomplete drop down to stop showing up?

Again, thanks for pointing me in the right direction!

Nick
 
The more I read about auto complete, the more I believe it wont work for me. I need something similar to the drop down list that the auto complete gives me, but this drop down list needs to be more like a listbox. Where I can set the list right then when the key is pressed, and I can trap the selected/changed index so that I can link it to a record number.

I could just use a combobox, but it would be sooooo ugly.
 
The functionaility of a combobox is probably what you're after, I believe you can handle the paint event of the combobox control and draw your own graphics in there...
 
Everything is working the way I want it to. The listbox pops up when I start typing in a textbox, full of the matches. I can click on an item in the list box and have all textboxs updated with data from the selected record. But if I am typing and just want to hit tab and go to the next textbox, it goes to the listbox. I want that to stop.

I have set tabstop to false, and I have set its tab index to the last control.

[EDIT] I have also toyed around with GotFocus and LostFocus

Here is a picture of what I am working with, I think it might clear up what I am talking about if you can see it.
my_form.jpg
 
Ok, I fixed it. When the user moved the mouse over the listbox I would set a variable so when the textbox gotfocus or lostfocus event gets triggered I test the value of that variable. Works like a charm.

Thanks for all the help. One way or another I learned something new. The auto complete function will come in handy!
 
Back
Top