[vb.net] How do I set a VB.Net ComboBox default value

I can not locate the correct method to make the first item in a combo box visible.

The app starts with an empty combo box. The user makes a radio box selection then clicks Go! (how original). The combo box is loaded via an LDAP query. All this is working just fine. The problem is the combo box still appears to the user to be empty. They must click the arrow to see the options.

How do I make the first option 'visible' after the users clicks Go!?

This question is related to vb.net

The answer is


If ComboBox1.SelectedIndex = -1 Then
    ComboBox1.SelectedIndex = 0    
End If

OR

you can write this down in your program

Private Sub ComboBoxExp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load
    AlarmHourSelect.Text = "YOUR DEFAULT VALUE"
    AlarmMinuteSelect.Text = "YOUR DEFAULT VALUE"
End Sub

so when you start your program, the first thing it would do is set it on your assigned default value and later you can easily select your required option from the drop down list. also keeping the DropDownStyle to DropDownList would make it look more cooler.

-Starkternate


Just go to the combo box properties - DropDownStyle and change it to "DropDownList"

This will make visible the first item.


You can try this:

Me.cbo1.Text = Me.Cbo1.Items(0).Tostring

because you have set index is 0 it shows always 1st value from combobox as input.

Try this :

With Me.ComboBox1
    .DropDownStyle = ComboBoxStyle.DropDown
    .Text = " "
End With

Another good method for setting a DropDownList style combobox:

Combox1.SelectedIndex = Combox1.FindStringExact("test1")

Much simpler solution, Select the Combo-box, and in the option of Selected item, select the item index (0 for the first item) and set it to be the default value in the combo box.