我将组合框绑定到新的数据源,它会自动选择第一个项目。我如何禁用它?
这是我的代码:
Private Sub item_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New config
con1 = New SqlConnection
con1 = obj.getcontion()
con1.Open()
da = New SqlDataAdapter("select * from item", con1)
ds = New DataSet
da.Fill(ds, "item")
cmbItem.DataSource = ds
cmbItem.DisplayMember = "item.itemname"
End Sub
答案 0 :(得分:0)
阻止选择combobox
。
cmbItem.DataSource = ds
cmbItem.SelectedIndex=-1
注意:您必须在SelectedIndex
与-1
绑定combobox
之后将datasource
属性设置为Select an item
。
显示自定义文字(" da = New SqlDataAdapter("select * from item", con1)
ds = New DataSet
da.Fill(ds, "item")
Dim firstRow As DataRow = ds.Tables("item").NewRow
firstRow("itemname") = "Select an item"
ds.Tables("item").Rows.InsertAt(firstRow, 0)
cmbItem.DataSource = ds
cmbItem.DisplayMember = "item.itemname"
cmbItem.SelectedIndex = 0
"),
0.0.0.0