Solved

combobox help

Posted on 2009-04-01
10
421 Views
Last Modified: 2013-11-08
Using:
Visual Studio 2008
Windows Forms (not ASP)
C#
.NET 3.5

I have a few comboboxes in my application. They are not databound. All of the items are loaded in manually. I do not want the user to be able to type in any text that does not exist in my list of items so I have the dropdownstyle = dropdownlist. this works fine. My problem is that I want the combobox to allow the user to type in multiple letters in the combobox text area and the box will go directly to that item. This does not work. It won't accept multiple characters.

Example:
If I have a list of cities sorted alphabetically..
.
.
Dallas
Detroit
.
.
Evansville
.
.
.
Say the user is looking for Detroit. In the combobox he types in a "D" and it goes to Dallas, then he types in an "E" and instead of looking at that as "DE" and going to Detroit it looks at it as just "E" and drops to Evansville, disreagrding the previous "D".

I've trid changing the autocomplete property but since I am using the dropdownlist style I am very limited here.

Any ideas?

Thanks.
0
Comment
Question by:kalittaair
[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
  • 5
  • 5
10 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24038980
0
 

Author Comment

by:kalittaair
ID: 24039450
Looking through this code I'm not sure how it will help. My combobox is style dropdownlist to prevent users from typing in text that is not in my list. As such, I cannot change the autocomplete property easily and when I do I get limited results. I tried implementing this from the example:
this.lstColors.AutoCompleteMode = ((System.Windows.Forms.AutoCompleteMode)((System.Windows.Forms.AutoCompleteMode.Suggest | System.Windows.Forms.AutoCompleteMode.Append)));
        this.lstColors.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;

And got the compile error:
Only the value AutoCompleteMode.None can be used when DropDownStyle is ComboBoxStyle.DropDownList and AutoCompleteSource is not AutoCompleteSource.ListItems.

Am I missing something?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24039561
i tried the sample as it is and its working as its explained
i typed in some wrong names and it didnt add the value to the combobox

change the dropdownstyle and give it a show
if you dont do it then only one keypress will be taken for a workd and the next key press will start searching for the new word in the combox (from the beginning)
0
Industry Leaders: 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:kalittaair
ID: 24040209
Thanks for your response but it is not working.

Firstly you said: "i typed in some wrong names and it didnt add the value to the combobox" - I'm not sure what you mean here. My combobox is not adding any values to itself or anything else. It is designed to simply let the user chose one of the items to be used in calcualtions later in the code.

Secondly:
My combobox is called comboFilterCity.

I changed the dropdownstyle of comboFilterCity from dropdownlist to dropdown and added from your sample code:
comboFilterCity.AutoCompleteMode = ((System.Windows.Forms.AutoCompleteMode)((System.Windows.Forms.AutoCompleteMode.Suggest | System.Windows.Forms.AutoCompleteMode.Append)));
comboFilterCity.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;

Now the autocomplete works fine but I can type in values that do not exist in my list. In using my original example, if I type in "DE" it goes to Detroit. However, if I then type an "X" it shows "DEX" in my combo's text box which does not match any item in my list. This is why I have it set to style dropdownlist. I don't want them to do this.

Should I be using additional code from the example? The rest of the code just looks like its creating the combobox, loading it, and setting some display properties.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24040254
but when you type in something which does not match it will show to the user no posibilities of match and so the user will have to correct his/her errors
i think this is the way autocomplete works where if something which does not match is typed nothing is displayed in the shortlist for combo
0
 

Author Comment

by:kalittaair
ID: 24040395
Yes, you are correct. It does not show the user any matching items. However, this does not stop the user from typing it and then hitting the SUBMIT button. The code in the SUBMIT button then accepts the text that exists in the box, regardless of whether or not it matches one of the items. It would be nice if the combobox would restrict users from typing in items that does not exist but still allow them to use the autocomplete that accepts multiple characters. Is there anyway to configure the combobox to do this? If not, it looks as though I'll have to loop through all the items in the compbobox upon hitting SUBMIT to do my own error checking. I was hoping not to have to do this.
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24040456
no you dont have to loop through the item list
combobox has findbytext and findbyvalue functions which you can use to see if the text exists in the list or not
http://www.obout.com/combobox/aspnet_options_find.aspx
0
 

Author Comment

by:kalittaair
ID: 24040509
I am not using ASP.NET. I am using Windows forms. Your example is ASP.NET. Does that matter?
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 24040546
0
 

Author Comment

by:kalittaair
ID: 24056671
Thanks!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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