Ubaid Ullah
Ubaid Ullah

Reputation: 13

combobox select first item on form load event.how i can change that it not select first item on form load

i load combobox on form load event in vb.net.it load id correctly and select first item(id) on load event in combobox.i want that it not select first item on load event.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim cmd As New SqlCommand
    Dim dset As New DataSet
    Dim dpt As New SqlDataAdapter

    Dim con As New SqlConnection
    con.ConnectionString = "data source=abc;initial catalog=LoginDB;integrated security=true"
    cmd.Connection = con
    con.Open()

    cmd.CommandText = "show_id"
    cmd.CommandType = CommandType.StoredProcedure
    dpt.SelectCommand = cmd
    dpt.Fill(dset, "tab")
    ComboBox1.DataSource = dset.Tables("tab")
    ComboBox1.DisplayMember = "id"

End Sub

i want combobox load "id" and not select the first item("id") on load event.but it load "id" correctly and select first item("id") on load event.

Upvotes: 0

Views: 1369

Answers (1)

Markus
Markus

Reputation: 22501

Insert the following code after assigning the DataSource. It resets the selection.

 ComboBox1.SelectedIndex = -1

Upvotes: 1

Related Questions