Problem with BindingNavigator

I have two problems with BindingNavigator

1.I use BindingNavigator to add records to my database, when use some controls(ComboBox,CheckBox,DataTimePicker) to binding data, I got some problem. if I don't click the control and select a value, I can't save the new record,  I get an exception
because som required fields are not set. I found even I select the value same as the current one, I still got the same exception, what should I do

2.When I'm adding a new record, If I press the AddNewItem again I get an exception
because som required fields are not set. I even can't use try...catch to deal with this exception, what should I do



Answer this question

Problem with BindingNavigator

  • Natallica

    Hi, thanks for your help. I want to set some default value to save time, I add code to set the CheckBox.Checked = False & set the DateTimePicker.Value = System.DateTimer.Now, but when I try to save the record, it still said the value is null. furthermore, unless I select a date diffrent with the default one, it always say the value is null.
  • dops

    I suspect that you have some null fields in your datarow which are not allowed to be null. Since you indicate you are using the DateTimePicker, I suspect it is one of the dates. Note that the DateTimePicker does not bind well to blank dates. Similarly, the ComboBox will return a null rather than an empty string if nothing is selected.

    As for the second issue, I have found that there can be an issue when the bindingsource receives an AddNew call when the current item is still new. In this case, you need to cancel the edit on the previous record before trying to add the new one. Here is some code I've used in the past.

    If Not MyDataGridView.CurrentRow Is Nothing AndAlso MyDataGridView.CurrentRow.IsNewRow Then
    MyBindingSource.CancelEdit()
    End If
    MyBindingSource.AddNew

    In both issues above, I suspect the source of the problem isn't in the Binding Navigator, but rather an issue with blank values (Null/Nothing) in your data.

    Jim Wooley
    http://devauthority.com/blogs/jwooley



  • Problem with BindingNavigator