|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Add New in Bindings Navigator problemVb.net 2005, Developer Edition.
When one creates a bindings navigator, one of the standard buttons created on the toolbar is Add New. Which works fine if you create a new item. However, if you don't enter any data, and click previous record or Move First, an error is generated. (there are previous records) In my case, in frmProducts I get "ProductCode cannot be null" Two questions 1) How do I trap for this error. Since theres no code in frmProducts.vb for the Previous Record button, I'm unsure of how to trap it. 2) How do I solve this issue? Thanks Vayse Hi Vayse,
You're getting the error, because the typed dataset doesn't allow null in the ProductCode column, and you didn't input anything into this field, so the exception is thrown. I assume that you're using a DataGridView to list all the data in the dataset. So in this case, the exception is thrown by the DataGridView instead of the BindingNavigator. If so, you can handle the DataGridView.DataError event to trap this. Here are the steps: 1. Click the DataGridView on the designer. 2. In the properties window, switch to event view. 3. Double click on DataError and it will create the event handler for you. 4. Add code in the event handler. Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." Hi Kevin
I'm not using the Datagridview, just a normal form. I don't see a DataError event in the form events, or in the ProductsBindingNavigator. What should I do in this case? Thanks Vayse Show quote "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message news:alu5cCo5FHA.2672@TK2MSFTNGXA02.phx.gbl... > Hi Vayse, > > You're getting the error, because the typed dataset doesn't allow null in > the ProductCode column, and you didn't input anything into this field, so > the exception is thrown. > > I assume that you're using a DataGridView to list all the data in the > dataset. So in this case, the exception is thrown by the DataGridView > instead of the BindingNavigator. If so, you can handle the > DataGridView.DataError event to trap this. Here are the steps: > > 1. Click the DataGridView on the designer. > 2. In the properties window, switch to event view. > 3. Double click on DataError and it will create the event handler for you. > 4. Add code in the event handler. > > Kevin Yu > ======= > "This posting is provided "AS IS" with no warranties, and confers no > rights." > Hi Vayse,
Do you mean that you have only a BindingNavigator on the form without showing the data? In this case the only thing we can do is to set the DataSet's EnforceConstraint property to true. However, this is not recommended. Since the ProductCode field doesn't allow null value, it's better for us to add a control to input data for it. Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." To make things clearer, I've set up a simple example.
I have a screenshot here http://h1.ripway.com/vayse/SampleProducts.bmp In fact, I've even put a zip file here http://h1.ripway.com/vayse/SampleProducts.zip So, what should I do to stop the error occuring? Thanks Vayse Show quote "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message news:HBor9gz5FHA.1236@TK2MSFTNGXA02.phx.gbl... > Hi Vayse, > > Do you mean that you have only a BindingNavigator on the form without > showing the data? In this case the only thing we can do is to set the > DataSet's EnforceConstraint property to true. However, this is not > recommended. > > Since the ProductCode field doesn't allow null value, it's better for us > to > add a control to input data for it. > > Kevin Yu > ======= > "This posting is provided "AS IS" with no warranties, and confers no > rights." > Hi Vayse,
Thanks for your code to reproduce it. I checked your code, to walkaround this issue, you have to validate the content of the ProductCode TextBox when adding a new row. You can handle the ProductCodeTextBox.Validating event to achieve this. Private Sub ProductCodeTextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ProductCodeTextBox.Validating If Me.ProductCodeTextBox.Text = String.Empty Then e.Cancel = True MessageBox.Show("No Product Code!") End If End Sub Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." Thanks, that will do the trick.
Show quote "Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message news:$hH$jLc6FHA.3788@TK2MSFTNGXA02.phx.gbl... > Hi Vayse, > > Thanks for your code to reproduce it. I checked your code, to walkaround > this issue, you have to validate the content of the ProductCode TextBox > when adding a new row. You can handle the ProductCodeTextBox.Validating > event to achieve this. > > Private Sub ProductCodeTextBox_Validating(ByVal sender As > System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles > ProductCodeTextBox.Validating > If Me.ProductCodeTextBox.Text = String.Empty Then > e.Cancel = True > MessageBox.Show("No Product Code!") > End If > End Sub > > Kevin Yu > ======= > "This posting is provided "AS IS" with no warranties, and confers no > rights." > |
|||||||||||||||||||||||