I have combo box on my windows form with several items in it. Ideally I would like to be able to change the data source, which is several different SQL Server tables, in the data grid view depending on what item is selected in the combo box.
Also, If there is a way to display a sql query in a data grid view that would be helpful as well.
Thanks.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text.Equals("DATA") Then
MessageBox.Show("DATA")
'DataSource = "Data Source=CSGFS01;Database=_CHRIS;Table=WorkOrders;Trusted_Connection=True;"
DataSource = "DATA"
End If
If ComboBox1.Text.Equals("DESIGN") Then
MessageBox.Show("DESIGN")
DataSource = "DESIGN"
End If
If ComboBox1.Text.Equals("INKJET") Then
MessageBox.Show("INKJET")
DataSource = "INKJET"
End If
If ComboBox1.Text.Equals("PRINT") Then
MessageBox.Show("PRINT")
DataSource = "PRINT"
End If
If ComboBox1.Text.Equals("QC") Then
MessageBox.Show("QC")
DataSource = "QC"
End If
End Sub
Private Sub TabPage1_Click(sender As Object, e As EventArgs) Handles TabPage1.Click
Me.Width = -20
Me.Height = -20
End Sub
Private Sub DataGridView1_CellContentClick_1(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM WorkOrders WHERE STATUS IS 'DATA'")
Me.WorkOrdersTableAdapter.Fill(Me._CHRISDataSet.WorkOrders)
End Sub
Aucun commentaire:
Enregistrer un commentaire