DataGridView DataBinding - SuspendBinding() & ResumeBinding()

What is the correct (best practice ) way of suspending databinding on a DataGridView to prevent lots of events flying around if you programmatically modify data in the underlying data source

I read somewhere that SuspendBinding and ResumeBinding don't work properly for DataGridViews because it involves 'complex data-binding'

Thank you in advance for your help.


Answer this question

DataGridView DataBinding - SuspendBinding() & ResumeBinding()

  • Vidit Mittal

    Many thanks.
  • Charlie Maitland

    In Whidbey there is support for this scenario for complex data binding as well.

    The BindingSource::RaiseListChangedEvents determines if list changed events are passed to its listeners. So if you bind your data grid view to the binding source you can set BindingSource::RaiseListChangedEvents to false, do the work, then set RaiseListChangedEvent to true and call BindingList::ResetBindings. ResetBindings will tell all the bound controls that the data was reset.

    this.dataGridView1.DataSource = bindingSource;

    bindingSource.RaiseListChangedEvents = false;

    //
    // do data intensive work here
    //

    bindingSource.RaiseListChangedEvents = true;

    // call ResetBindings so the data grid view knows the list was changed

    bindingSource.ResetBindings();

    Hope this helps.

  • coolbiker

    In Whidbey there is support for this scenario for complex data binding as well.

    The BindingSource::RaiseListChangedEvents determines if list changed events are passed to its listeners. So if you bind your data grid view to the binding source you can set BindingSource::RaiseListChangedEvents to false, do the work, then set RaiseListChangedEvent to true and call BindingList::ResetBindings. ResetBindings will tell all the bound controls that the data was reset.

    this.dataGridView1.DataSource = bindingSource;

    bindingSource.RaiseListChangedEvents = false;

    //
    // do data intensive work here
    //

    bindingSource.RaiseListChangedEvents = true;

    // call ResetBindings so the data grid view knows the list was changed

    bindingSource.ResetBindings();

  • DataGridView DataBinding - SuspendBinding() & ResumeBinding()