Question:
How do you code this?
Lamecore
2008-12-03 16:48:55 UTC
Hello everyone i'm coding a Windows Form in VB.Net (Visual Basic). I have been trying to figure out how to dynamically update my Combo Box on the form itself without pressing a Command Button, by entering a partial name into a Text Box. For example, i start typing "jo" into the Text Box and then click on the Combo Box drop down arrow. I should get a list of names that start with "jo". For example, i'm using SQL to extract data, so on my SQL table i would have names like "Jordan M", "John D", "Jole E", So those name should begin to appear in my Combo Box drop down list. Anyone have any ideas?
Four answers:
ucftrev
2008-12-03 17:01:58 UTC
You can use AJAX to do this, assuming that you want the code to check the database after each character is typed.



You can go to the site below to get some code examples of what you are trying to do.
Wooster11
2008-12-03 17:06:52 UTC
Ideally, you would need to do the following:



Store all your data needed for the combo box in a data table.



You'll want to then bind your combo box to some sort of collection like an Array List.



On the text changed event of the combo box, re-populate your collection with the proper values from the data table and refresh the combo box. Once they click the drop-down, you should only see those names.



You could also capture the drop down event and only show those names at that point.



Either way you do it, it will always require you to clear your combo box and re-populate the combo box with what you want. There isn't any kind of auto-filtering in place.
TheMadProfessor
2008-12-04 06:48:11 UTC
Only problem I can see with this is, if your data is on a network or web app, this could create a LOT of traffic over your connection. The reason is, if you want to dynamically update your datalinked combo box, you would have to fire an event every time your text box changes (essentially on every keypress) to sent a new query with the current value of the text box as the comparator of a LIKE clause in the WHERE of your query. This would cause a whole new resultset to be sent back with every keystroke - not necessarily an issue if it's a local database, but could make for some major lag time if sent over some remote communication channel.
Tasm
2008-12-03 16:55:16 UTC
I think you can use an on.change for the text box and update the value of the combo box to the value of the text box.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...