DtaGridView - Add DataBinding using bindingsource

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

Hello all,

I am relatively new to windows forms and I am trying to make this work
(pseudo code):

Create bindingsource.
Set DataSource property of bindingsource to generic list
Check to see if datasource of datagridview is null
if it isn't add databindings

i.e.

private BindingSource bs = new BindingSource();
bs.DataSource = objList.CollBuildings;

if (dgvBuildings.DataBindings["DataSource"] == null)
{
dgvBuildings.DataBindings.Add(new Binding("DataSource", bs, ""));
} // end if

It doesn't error, but I get no data displayed in the grid. This does
work:
dgvBuildings.DataSource = bs;

Is there some advantage to using the DataBindings.Add as opposed to
setting the datasource directly?

Thanks for your help and have a great day!
Ryan
 
Back
Top