我有一个带有数据源的数据网格视图和一个访问表。datagridview 已填充且完美,但现在我想创建一个带有过滤器可能性的额外组合框。
这是在我的页面加载功能中:
Private Sub ArchiefFacturatie_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CharelIjsDataSet.tblFactuur' table. You can move, or remove it, as needed.
Me.TblFactuurTableAdapter.Fill(Me.CharelIjsDataSet.tblFactuur)
'Filling comboxbox part skipped
End Sub
此时组合框也填充了datagridview。现在我在组合框上创建了一个 on selectChange 操作。
我不知道如何解决这个问题,但我已经尝试过了:
Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles ComboBox1.SelectionChangeCommitted
'Ophalen id artikel
Dim klantid As Integer
klantid = ComboBox1.SelectedValue
Dim klantidstr As String
klantidstr = klantid.ToString
'Via query overige gegevens ophalen
' OLEDB select query
Dim myConnection As OleDbConnection
Dim DBpath As String = "C:\Facturatie\CharelIjs.accdb"
Dim sConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBpath & ";Persist Security Info=True"
myConnection = New OleDbConnection(sConnectionString)
myConnection.Open()
Dim SQLstr As String
SQLstr = "SELECT * FROM tblKlant WHERE KlantID = @id"
Dim cmd As New OleDbCommand(SQLstr, myConnection)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
cmd.Parameters.Add("@id", OleDbType.VarChar)
cmd.Parameters(0).Value = klantid
Try
da.Fill(ds, "tblKlant")
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Can't load Web page" & vbCrLf & ex.Message)
Return
End Try
DataGridView1.DataSource = ds.Tables("tblKlant")
End Sub