Solved

Limit to the list

Posted on 2003-10-23
6
277 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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