Question Combo box input

audio_uphoria

Active member
Joined
Jan 28, 2009
Messages
31
Programming Experience
Beginner
Hello, I'm setting up a program where I would like the user to be able to select a state from a combo box. I can not figure out how to allow to select the abbreviation from the drop down list and also allow them to type a letter and it will select the state from the state or just allow them to type the full abbreviation that would match what is already in the list. It is supposed to be in the drop down list style. I would also like to confirm that the user has chosen a state before allowing them to click a submit button but I'm not sure how to go about confirming it. Any help appreciated. Thanks.

VB.NET:
Private Sub FrmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Inserts state abbreviations in combo box
        cboState.SelectedItem = " "
        cboState.Items.Add(" ")
        cboState.Items.Add("AL")
        cboState.Items.Add("AK")
        cboState.Items.Add("AZ")
        cboState.Items.Add("AR")
        cboState.Items.Add("CA")
        cboState.Items.Add("CO")
        cboState.Items.Add("CT")
        cboState.Items.Add("DE")
        cboState.Items.Add("DC")
        cboState.Items.Add("FL")
        cboState.Items.Add("GA")
        cboState.Items.Add("HI")
        cboState.Items.Add("ID")
        cboState.Items.Add("IL")
        cboState.Items.Add("IN")
        cboState.Items.Add("IA")
        cboState.Items.Add("KS")
        cboState.Items.Add("KY")
        cboState.Items.Add("LA")
        cboState.Items.Add("ME")
        cboState.Items.Add("MD")
        cboState.Items.Add("MA")
        cboState.Items.Add("MI")
        cboState.Items.Add("MN")
        cboState.Items.Add("MS")
        cboState.Items.Add("MO")
        cboState.Items.Add("MT")
        cboState.Items.Add("NE")
        cboState.Items.Add("NV")
        cboState.Items.Add("NH")
        cboState.Items.Add("NJ")
        cboState.Items.Add("NM")
        cboState.Items.Add("NY")
        cboState.Items.Add("NC")
        cboState.Items.Add("ND")
        cboState.Items.Add("OH")
        cboState.Items.Add("OK")
        cboState.Items.Add("OR")
        cboState.Items.Add("PA")
        cboState.Items.Add("RI")
        cboState.Items.Add("SC")
        cboState.Items.Add("SD")
        cboState.Items.Add("TN")
        cboState.Items.Add("TX")
        cboState.Items.Add("UT")
        cboState.Items.Add("VT")
        cboState.Items.Add("VA")
        cboState.Items.Add("WA")
        cboState.Items.Add("WV")
        cboState.Items.Add("WI")
        cboState.Items.Add("WY")

    End Sub
 
Hi audio_uphoria, if I understand you correctly, in the properties window, all you need to do is find the auto_complete_source and change to it ListItems, and auto_complete_mode - SuggestAppend. FYI, you can enter the items in the designer if you want to save some code writing, in the properties window look for (collection) and you can enter them here.


Hope this helps.
 
Hey you helped alot new guy but that will only work if it is in drop down style: drop down. I need it to be in drop down list style. Jugalo what exactly did you mean dropdownlist would do automatically? Cause its not allowing me to enter text into a box. Also guys I need to figure out how to validate this while clicking a submit button. Thanks for you help.
 
combo box answer

audio_uphoria,

I think there's some confusion as to your wording; I misunderstood your question as well.

Hopefully this will clear it up:

You are talking auto-complete, so use the auto-complete properties. You can press F1 to bring up help, or google "msdn ComboBox Databind" to get the skinny on them (MSDN Library Help).

Short answer, you need to create at the very least a string array, or some other data object (i.e. a List), populate that with your data, then

set cboState.DataSource = myStringArray.

Then call cboState.DataBind

Poof, your combobox is populated.

Then, set the AutoCompleteMode property to, um, Append? I'm not sure what behavior you want, so try em all, or read the help.

Then, in your submit button's code, you verify that the .SelectedIndex is set so you know that a valid choice has been made, if not throw an exception or show an error or whatever suits you.

Hope that makes sense.

Conversely, you can just set the style to list and force the user to press a button or click.
 
Back
Top