Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
.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.
Comments
Anonymous
November 05, 2006
Thanks for the article, and I've a question. How can I update the BindingSource from the DB?Anonymous
November 06, 2006
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.