a PROPER Searchbox? Searching a listbox..... - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

rdbandit1459rdbandit1459 Posts: 12Member
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.