Search code examples
c#datagridviewdatatabledatasetbindingsource

DataBinding between DataSet and DataGridView in C#


I currently have a DataGridView on a form which I want to use with a DataTable in a DataSet, populated from a SQlite database (using System.Data.SQlite).

So, I have a DataAdapter between the database and DataSet and can set the DataGridView data source directly as the DataTable. This displays fine.

My question is this: Why would I want to use a Binding Source here? Many tutorials have said you can use it or not. But is there any use for it, other than adding an extra step?

Also, if I want the database to be updated when the DataGridView is changed, how can this be done? Is the DataSet automatically updated - so I just need to tell the DataAdapter to update? Or is there where a binding source is useful?

Thanks!


Solution

  • For anyone else searching for this, I found a good description of why to use a Binding Source here.

    Similarly, this explains saving/restoring changes made in the DataGridView.

    Hope that helps someone!