SYSK 127: ResetBindings To the Rescue!

.NET 2.0 came with a lot of cool (new and improved) controls, one of them is the System.Windows.Forms.BindingNavigator and the BindingSource class.  The only problem I found so far with this control is that if in the Load event you bind it to a BindingSource with zero elements, and then try to add an object by clicking “Add New” icon, the controls on the form will not be refreshed with new data.

 

The solution I use is to call BindingSource.ResetBinding when the count = 1 (i.e. when it’s the first time we add an object after binding it to an empty list).

To see it for yourself, comment out

_bs.ResetBindings(false);

line in

private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)

method and run the project (code attached).  Then click yellow plus icon to add new object. 

 

Now uncomment the ResentBinding call and run again – the app behaves as expected.

 

BindingExample.zip