Solved

Limit to the list

Posted on 2003-10-23
6
278 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:mrong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
jlach earned 50 total points
ID: 9610102
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
0
 

Author Comment

by:mrong
ID: 9611318
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.
0
 
LVL 1

Expert Comment

by:jlach
ID: 9612596
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mrong
ID: 9613973
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
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9616604
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.
0
 

Author Comment

by:mrong
ID: 9616647
I tried that already. But the current data won't be show up in the ComboBox. Those list Items are there.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question