Welcome to MSDN Blogs Sign in | Join | Help

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.

 

Published Tuesday, May 16, 2006 5:55 AM by irenak
Attachment(s): BindingExample.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SYSK 127: ResetBindings To the Rescue!

Monday, November 06, 2006 7:45 AM by Oss

Thanks for the article, and I've a question.

How can I update the BindingSource from the DB?

# SYSK 127: Reply to Oss

Monday, November 06, 2006 1:12 PM by irenak

I'm not quite clear on your question.

Take a look at the code sample provided at http://msdn2.microsoft.com/en-us/library/fbk67b6z(VS.80).aspx

If that is not what you were looking for, then please provide more information about what you're trying to do.  Code sample/psuedo-code is always helpful.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker