Since I work with .net 2.0 databinding I run into one problem after the other. Unfortunatly things that should work in a nice way only do on the surface but not in detail. At least that is my impression. The AddItem Button of the BindingNavigator seems to be unusable. I hope I am wrong and there is a way to solve the problem.
To reproduce the problem:
1. Add a DataGridView and a BindingNavigator to a Form
2. Bind both to a BindingSource
3. The DataSource of the BindingSource is a DataTable that contains at least 1 column where AllowDBNull = false
4. Run the Application
5. Press the AddNewItem Button in the BindingNavigator
6. Press the AddNewItem Button in the BindingNavigator
7. NoNullAllowedException occurs
I did not find a way to catch and handle this Exception, so I disabled the built in beavior of the BindingNavigator and handled the click event of the button (see also the thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=857224&SiteID=1&mode=1):
private void OnAddNewClick(object sender, EventArgs e)
{
DataRowView r;
try
{
r = myKeySource.AddNew() as DataRowView;
}
catch (NoNullAllowedException eX)
{
..
}
catch (ConstraintException eX)
{
..
}
}
Now the problem seemed to be solved. But an other one occured. If I first add a row by using the BindingNavigator (that uses my code above) and then use the "new row line" by clicking it, the NoNullAllowedException occurs again. I am not able to find a way to solve this problem.
Please help by a direct answer or a link that handles these bugs.
Thank you very much,
Andreas