"fill as you type" combobox

  • Thread starter Thread starter VMI
  • Start date Start date
V

VMI

How can I create a comboBox that will display the first item that begins
with the group of letters I type? In my current combobox (it's a
DropDownList), if I press the letters "S" and "A" consecutively, it'll
display the first item that starts with "S" and then the first item that
begins with "A". What can I do so that if I type those two letters, iit'll
display the first item that starts with "SA". And if I then press "T", it'll
display the first item with "SAT".

Thanks.
 
VMI,

You will have to hook up to the TextChanged event. When the text
changes, filter the list (using a DataView) and take the text of the first
result, setting the text of the combo box to that. You would have to have a
check in your handler of course, to determine whether or not to handle the
event (when you change the text, another TextChanged event would be fired).

Of course, you also want to highlight the text that they typed in, and
place the caret at the appropriate position.

You might also want to consider the autocomplete drop down box, which is
made available in 2.0 through a managed interface, or through the P/Invoke
layer in .NET 1.1 and before.

Hope this helps.
 
I think I saw a Windows Forms solution with this functionality
at CodeProject.


--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET (e-mail address removed)
URL http://www.metromilwaukee.com/clintongallagher/



Nicholas Paldino said:
VMI,

You will have to hook up to the TextChanged event. When the text
changes, filter the list (using a DataView) and take the text of the first
result, setting the text of the combo box to that. You would have to have a
check in your handler of course, to determine whether or not to handle the
event (when you change the text, another TextChanged event would be fired).

Of course, you also want to highlight the text that they typed in, and
place the caret at the appropriate position.

You might also want to consider the autocomplete drop down box, which is
made available in 2.0 through a managed interface, or through the P/Invoke
layer in .NET 1.1 and before.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

VMI said:
It's for a Windows ComboBox.
 
Back
Top