DtaGridView - Add DataBinding using bindingsource

Discussion in 'Microsoft Dot NET Framework Forms' started by Ryan, May 14, 2008.

  1. Ryan

    Ryan Guest

    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
     
    Ryan, May 14, 2008
    #1
    1. Advertisements

  2. Ryan

    Ryan Guest

    Hi RobinS!

    That makes sense, thanks for your help!

    Ryan
     
    Ryan, May 15, 2008
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Visual Basic 2005: Windows Forms BindingSource

    Guest, Oct 24, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    701
    Bart Mermuys
    Oct 24, 2005
  2. Guest

    Adding Record Using BindingSource and BindingNavigator

    Guest, Jun 15, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    769
    Guest
    Jun 15, 2006
  3. Marc Vangrieken

    Databinding: "BindingSource - field" syntax

    Marc Vangrieken, Aug 9, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    524
    Marc Vangrieken
    Aug 11, 2006
  4. Newish

    Databinding and Bindingsource issue

    Newish, Oct 15, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    238
    Newish
    Oct 15, 2006
  5. Rajat

    C# 2.0 DataBinding using the BindingSource in user controls

    Rajat, Oct 27, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    892
    Rajat
    Oct 27, 2006
Loading...

Share This Page