DtaGridView - Add DataBinding using bindingsource

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top