a PROPER Searchbox? Searching a listbox.....

I would like to make a searchbox that searches a listbox.
When the text is changed in the searchbox the listbox is updated with the resulting mathches!

I am using the Following code, but this only works for a partial match. When the user types to many words or gets and exact match.... the program freezes!

Can anyone help? Here is the code I am using:

private void txtSearch_TextChanged(object sender, System.EventArgs e)
// search the array list for matching records as the user types

// clear the results list

// make sure there is something to search for
if (txtSearch.Text != "")
foreach(Person p in myAddressBook)
// try a partial string match, looking at the first few letters of each name only
if (p.Name != "")
if (p.Name.Substring(0, txtSearch.Text.Length) == txtSearch.Text)
// stick matches in the listbox


there must be a better way!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!