我在combobox.combobox上根据表单加载事件正确搜索了名称,但它在表单加载事件上选择了第一项,并且还在第一项的基础上进行了搜索。如何在表单加载事件中停止此选择? ?
我使用combobox1.selectedindex = -1。这不会显示组合框中的任何项目,而是根据组合框中的第一项进行搜索...
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
Dim con As New SqlConnection
con.ConnectionString = "data source=abc;initial
catalog=LoginDB;integrated security=true"
cmd.Connection = con
con.Open()
cmd.CommandText = "search_data"
cmd.CommandType = CommandType.StoredProcedure
Dim dset As New DataSet
Dim dpt As New SqlDataAdapter
dpt.SelectCommand = cmd
dpt.Fill(dset, "tab")
ComboBox1.DataSource = dset.Tables("tab")
ComboBox1.DisplayMember = "ID"
ComboBox1.SelectedIndex = -1
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As
EventArgs) Handles ComboBox1.SelectedIndexChanged
cmd.CommandText = "show_date"
cmd.CommandType = CommandType.StoredProcedure
p = New SqlParameter
p.ParameterName = "@id"
p.Value = ComboBox1.Text
cmd.Parameters.Add(p)
Dim dset As New DataSet
Dim dpt As New SqlDataAdapter
dpt.SelectCommand = cmd
dpt.Fill(dset, "tab")
If dset.Tables("tab").Rows.Count > 0 Then
nameTextBox.Text = dset.Tables("tab").Rows(0)("name")
End If
End Sub
我希望在加载表单时不进行搜索,而当用户更改项目时在搜索...