Limit to the list

Greetings,

I have a ComboBox defined as "DropDown" style. I want to limit the user's input, so the user can only type/pick the item from the drop down list.

Thanks in Advance.
mrongAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jlachCommented:
You would want to do this either using the KeyUP event or the TextChanged event ... loop throug the items in the combo box (foreach.... in ....) .. if the strings found, they can type, if not, stop them from typing.. if using keyup.. you can use e.handled = true .. if using textchanged, make sure you keep a variable of the text before the text changed event (KeyDown maybe?) and then set the text back to that variable

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrongAuthor Commented:
Please explain "if the strings found, they can type, if not, stop them from typing". Do you mean check the user's input character by character or the whole string? Please provide more details.
Thanks.
jlachCommented:
check the current string typed in the combo box against all items in the combo box, if the string is not found to be contained in any of the items, set the text back to what it was before the keypress
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

mrongAuthor Commented:
Hi jlach,

I found a sample code at the following URL and I think it fits my needs. But I am not sure how to put into my code. Could you help me? Thanks.

http://www.thecodeproject.com/cs/combobox/csautocomplete.asp
SRigneyCommented:
You may be ok with just changing the DropDownStyle to DropDownList.
This prevents typing in new items, and as the user types the list finds the closest item to the typing.
mrongAuthor Commented:
I tried that already. But the current data won't be show up in the ComboBox. Those list Items are there.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.