im just a noob vb programmer and im now making a thesis project (library system) im just wondering if any1 know how to do that (see title) in visual basic coz im planning to put that in our text box for searching books or student info for easier searching. help me pls ^^

Dani AI

Generated

Three practical ways to get a Yahoo-style suggestion box in Visual Basic, depending on what you need and which VB you’re using: the built-in ComboBox AutoComplete (VB.NET), a lightweight TextBox + ListBox overlay (fast and easy to control), or a TextBox + ListView when you need multi-column or rich formatting (as pointed out). Keep one rule: show the friendly text to the user but always keep the record ID (hidden) so a selection can map back to the database record.

Suggested implementation (TextBox + ListBox overlay)

  • Keep a small in-memory cache for small tables, or run a server-side, parameterized query that returns only the top N matches for each keystroke (to avoid thumbnails of rows).
  • Debounce typing (200–300 ms) with a Timer or async delay so the app does not query on every keypress.
  • Filter the data (prefix match for speed) and bind the results to a ListBox whose items are small objects containing both Display and Id (use DisplayMember/ValueMember). Position and size the ListBox so it appears anchored under the TextBox.
  • Keyboard UX: Up/Down to change selection, Enter to accept (write the Display back to the TextBox and the Id to a hidden field), ESC to hide, click to select. Hide the list on LostFocus unless a click is in progress.

Practical tips and pitfalls

  • Use parameterized SQL to avoid injection and always limit results. Index the searched column or use full-text search if fuzzy matching is required. For large datasets, run the search on the server and return only needed columns. Run DB calls on a background thread and marshal results to the UI thread. For nicer UI, owner-draw the list to highlight the matched substring. Note ’s ComboBox tip — it’s simplest if built-in autocomplete meets the UI needs; use ’s sample as a reference but ensure it preserves the record ID.

Minimal VB.NET pattern (binding a filtered DataView)

' tmrDebounce interval = 250ms, dt is DataTable with Id,Display
Private Sub txtSearch_TextChanged(...) Handles txtSearch.TextChanged
  tmrDebounce.Stop() : tmrDebounce.Start()
End Sub

Private Sub tmrDebounce_Tick(...) Handles tmrDebounce.Tick
  tmrDebounce.Stop()
  Dim term = txtSearch.Text.Trim().Replace("'", "''")
  If term = "" Then lstSuggestions.Visible = False : Return
  Dim dv As New DataView(dt) : dv.RowFilter = $"Display LIKE '{term}%'"
  lstSuggestions.DataSource = dv.ToTable(False, "Id","Display")
  lstSuggestions.DisplayMember = "Display" : lstSuggestions.ValueMember = "Id"
  lstSuggestions.Visible = True
End Sub

If the dataset is large or fuzzy matching is needed, prefer server-side search with an indexed column or full-text search to keep the UI responsive.

Recommended Answers

All 9 Replies

Here is what you can do.
Put a textbox on a form. And then place a listview control below. Now write the search code on the keydown of the textbox to show the results in the listview control below.

I think you mean is the combo box but not the combo box in the default given. just go to the components then check the Microsoft Windows Components (I think it is sorry no VB here in the cafe) if you can see the combobox then thats it. what you have to do is to load the data from the database to that combobox then when put an entry on that combobox it will give you a suggestions.
hope it would help. if you still don't get it just give me a buzz

I don't mean combobox. List view gives more control over how you want to represent the data. It is best suited when you need custom format for your data. Its can act as a auto-complete solution.

Hi,
Check the attached example, I hope this is what you are looking for.

This is good provided you can add the id and display column.

Hi ki.net

Thanks a lot for for your support
it was really a timely help

Please mark thread as solved if your problem has been answered.

HI!kb.net tnx for the sample, it helps us a lot

thanks for sharing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.