Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

combobox help

Posted on 2009-04-01
10
Medium Priority
?
425 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
 

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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 2000 total points
ID: 24040546
0
 

Author Comment

by:kalittaair
ID: 24056671
Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 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