If you have a DataGridView that is bound to a DataView (someDataTable.DefaultView).
..and a number of edits are performed on rows in the underlying DataTable from code.
Is it possible to defer the updating of the DataGridView until you decide that you are finished editing rows?
As it is, the DataGridView is updated after every edit, which, if you don't require instant feedback, is inefficient and a little visually jarring if you are updating many rows in the DataTable one after the other.
In order to be able to temporarily suspend data binding, you'll have to put a BindingSource
between your DataGridView
and your DataView
. By setting the RaiseListChangedEvents
property of the BindingSource
to false, changes in the underlying source are not notified to the DataGridView
. You can drag & drop a Bindingsource
component from the toolbox in the design view. I tried to set up the data sources via the designer but it didn't work, so I did it in code:
bindingSource1.DataSource = someDataTable.DefaultView;
dataGridView1.DataSource = bindingSource1;
To suspend data binding, just set the RaiseListChangedEvents
property to false:
bindingSource1.RaiseListChangedEvents = false;
To resume data binding, just set the RaiseListChangedEvents
to true and reset the bindings so the display is updated:
bindingSource1.RaiseListChangedEvents = true;
bindingSource1.ResetBindings(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With