How to set a default value in the ComboBox control?

0

Use the ComboBox control and add several values through the properties window in the Item part which allows you to add in the form of a collection. The question I have is how can I do so that when I start the application, the first option of the ComboBox is the first value that is added in the collection.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Text = TextBox1.Text & " - " & ComboBox1.Text
    End Sub
End Class
    
asked by Popplar 10.04.2017 в 05:14
source

2 answers

3

I'll follow the following:

Place the property DropDownStyle from the combobox as DropDownList is to do the following

miComboBox.DropDownStyle = ComboBoxStyle.DropDownList
miComboBox.SelectedIndex = 0

with the two lines above (in order of appearance) you indicate to the combobox that (say) you restrict the values in item and that you set the first element as selected (with -1 -less one- you indicate none).

    
answered by 10.04.2017 / 05:26
source
1

I consider Roberto León Oramas's answer quite adequate, but in the face of the concern of Comrade Popplar of "and where I place the code".

It may be in the Load Event of the Form you are working on.

    
answered by 10.04.2017 в 14:48