Confused on how to handle a BindingSource, Dataset, TableAdapter that is bound to a DGV?

I do not know how to update a DataGridView that is bound thru the DEsigner. I have to have this dgv bound thru the designer just because it's easier and quicker. However, the dgv is loaded based of of 2 parameter values (a 4 digit year and a 2 digit month) on the form when it loads. The user has control of these two parameters and can change them anytime. For a month that has no data, obviously the dgv will be empty, when there is data, I'm not sure how to delete and update the grid.

The main difference between this dgv and others that I have worked with via the designer, is that executes a Stored Procedure because of the parameters. I tried using the BindingSource Filter property but it did not like my string that I was passing it.

Anyway, can someone please show me the easiest and most efficient way to handle all updates to a designer bound DataGridView?

Who is Participating?
adriankohwsConnect With a Mentor Commented:
Something like this:

Private dt As New DataTable()
Private bs As New BindingSource()

Private Sub Form1_Load(sender As Object, e As EventArgs)
      dt.Columns.Add("id", GetType(Integer))
      dt.Columns.Add("country", GetType(String))

      dt.Rows.Add(New Object() {1, "Belgium"})
      dt.Rows.Add(New Object() {2, "France"})
      dt.Rows.Add(New Object() {3, "Germany"})
      dt.Rows.Add(New Object() {4, "Spain"})
      dt.Rows.Add(New Object() {5, "Swiss"})
      dt.Rows.Add(New Object() {6, "United Kingdom"})

      bs.DataSource = dt
      dataGridView1.DataSource = bs
End Sub

Private Sub textBox1_TextChanged(sender As Object, e As EventArgs)
      MessageBox.Show("DataSource type BEFORE = " & dataGridView1.DataSource.[GetType]().ToString())

      bs.Filter = String.Format("country LIKE '%{0}%'", textBox1.Text)

      MessageBox.Show("DataSource type AFTER = " & dataGridView1.DataSource.[GetType]().ToString())
End Sub
BlakeMcKennaAuthor Commented:
Thank you! That worked perfect and now I understand how the BindingSource gets updated automatically.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.