C# – DataGridView does not display DataTable

cdatagridviewdatatablesqlitesystem.data.sqlite

I've got the following code which I think ought to be binding a DataTable to a DataGridView, but the DataGridView shows up empty. The DataTable definately has rows, so I assume that I am binding the DataSource incorrectly some how. Does anyone see what is wrong with this:

DataBase db = new DataBase(re.OutputDir+"\\Matches.db");
MatchDBReader reader = new MatchDBReader(db.NewConnection());

BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = reader.GetDataTable();

this.dataGridView1.DataSource = bindingSource.DataSource;
  • The first line simply gets a handle to the DB that I'm pulling data from.
  • The next line is a provides a class for reading from that same db – in particular it exposes the GetDataTable method with returns the data table that I intend to put into the DataGridView.
  • The next line is uninteresting…
  • The 4th line attempts to grab the DataTable – QuickWatch indicates that this is working…
  • The final line is where I assume i've screwed up…my understanding is that this binds the DataTable to the DataGridView GUI, but nothing shows up.

Any thoughts?

Best Answer

Try binding the DataGridView directly to the BindingSource, and not the BindingSource's DataSource:

this.dataGridView1.DataSource = bindingSource;