[RESOLVED] Assigning new DataSource to DataGridView
After correctly displaying data from one DataSource in my DataGridView I am assigning a different DataSource and calling the Refresh method but the new data is not rendering. I have confirmed new DataSource's dataset contains values. How can this be done?
Initial load of DGV:
Private Sub frmCodesetViewer_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.CodeDescriptionTableAdapter1().Fill(Me.DsCodesets.CodeDescription)
Me.CodeValuesTableAdapter().Fill(Me.DsCodesetValues.DataTable1, "A1")
DataGridView1.DataSource = DsCodesetValues.DataTable1
Dim r As DataRow = Me.DsCodesets.CodeDescription.Rows(0)
txtCSDesc.Text = r.Item("Description")
ComboBox2.Text = "(no filter)"
End Sub
Changing data source:
Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
'Dim filter As String = "%" & ComboBox2.SelectedValue & "%"
Dim filter As String = "%" & "Least" & "%"
Me.FilteredValuesTableAdapter1.Fill(Me.DsFilteredValues1.DataTable1, SelectedCodeset, filter)
DataGridView1.DataSource = DsFilteredValues1
DataGridView1.Refresh()
Dim r As DataRow = Me.DsCodesets.CodeDescription.Rows(ComboBox1.SelectedIndex)
txtCSDesc.Text = r.Item("Description")
End Sub
Bob
Re: Assigning new DataSource to DataGridView
Is your DataGridView.AutoGenerateColumns = True ?
Re: Assigning new DataSource to DataGridView
I have tried setting AutoGenerateColumns to True and also to False, neither worked. Also looked but Bind method does not exist. Could not figure out how to I could use the DataBindings method but this seems like overkill. Should be a straight forward solution I would think but it beats the hell outa me :(
Re: Assigning new DataSource to DataGridView
Oh, in the line
Code:
DataGridView1.DataSource = DsFilteredValues1
I think you meant
Code:
DataGridView1.DataSource = DsFilteredValues1.DataTable1
Re: Assigning new DataSource to DataGridView
That did the trick! Not sure how I missed that. Thank you, Tim. Much appreciiated :D
Bob
Re: Assigning new DataSource to DataGridView
My pleasure. We've all done it in one way or the other on controls like DataGridViews where you can point it at different object types.
Please mark the thread resolved.