|
-
Mar 13th, 2014, 07:14 AM
#1
Thread Starter
Junior Member
[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
Last edited by bobmc; Mar 13th, 2014 at 07:23 AM.
Reason: adding code snippets
-
Mar 13th, 2014, 07:48 AM
#2
Addicted Member
Re: Assigning new DataSource to DataGridView
Is your DataGridView.AutoGenerateColumns = True ?
Last edited by thetimmer; Mar 13th, 2014 at 07:54 AM.
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
-
Mar 13th, 2014, 08:09 AM
#3
Thread Starter
Junior Member
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
-
Mar 13th, 2014, 08:41 AM
#4
Addicted Member
Re: Assigning new DataSource to DataGridView
Oh, in the line
Code:
DataGridView1.DataSource = DsFilteredValues1
I think you meant
Code:
DataGridView1.DataSource = DsFilteredValues1.DataTable1
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
-
Mar 13th, 2014, 08:44 AM
#5
Thread Starter
Junior Member
Re: Assigning new DataSource to DataGridView
That did the trick! Not sure how I missed that. Thank you, Tim. Much appreciiated 
Bob
-
Mar 13th, 2014, 08:54 AM
#6
Addicted Member
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.
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|