简体   繁体   中英

how to create textbox for searching like Google textbox style

Just as simple as this, I need to search an array that is binded to listbox, and user will type the text in a text box, something like Google search text box does.

This is for Windows Application using C# (3.5)

Any idea?

You need to use ComboBox, it has autocomplete

This is simple

WinForms TextBox controls have an AutoComplete property. This behaves the same as the Google TextBox. Here is an example:

http://csharpdotnetfreak.blogspot.com/2009/01/winforms-autocomplete-textbox-using-c.html

Assuming the array is sorted in alphabetical order.

Just handle the TextChanged event for the TextBox and whenever it changes you use ListBox.FindString to find the first item in the ListBox that starts with that string and then call ListBox.TopIndex with the index of that item to make that be the top visible item in the ListBox .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM