本文介绍了如何在绑定之前设置组合框的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Public Sub Bind(ByVal strExcelFilePath As String)
' ComboBox1.Items.Insert(0, New ListViewItem("All", 0))
Dim strin As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & strExcelFilePath & ";Extended Properties=""Excel 12.0;HDR=YES"";"
Dim con As OleDbConnection = New OleDbConnection(strin)
If con.State = ConnectionState.Closed Then
con.Open()
Dim command As OleDbCommand = New OleDbCommand()
command.CommandText = "Select Distinct Department from [Sheet1$]"
command.Connection = con
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
adapter.SelectCommand = command
Dim dt As New DataSet
adapter.Fill(dt, "DT")
ComboBox1.DisplayMember = dt.Tables(0).Columns(0).ColumnName
ComboBox1.DataSource = dt.Tables(0)
ComboBox1.Items.Insert(0, ("All"))
End If
推荐答案
ComboBox1.SelectedIndex = 2
或
or
ComboBox1.SelectedValue = "my choice"
这篇关于如何在绑定之前设置组合框的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!