如何禁用在vb.net中自动选择的组合框

时间:2017-01-02 09:56:54

标签: vb.net

我将组合框绑定到新的数据源,它会自动选择第一个项目。我如何禁用它?
这是我的代码:

 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

1 个答案:

答案 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