[quoted text, click to view] "Jeronimo Bertran" <jeronimo.bertran@newsgroup.nospam> wrote in message
news:Xns9772E53CC19A5publicjbbertrancom@207.46.248.16...
>I created a form that include a BindingNavigator. My BindingSource has
> some required fields. If I use the bindingNavigator AddNewItem the bound
> controls are cleared. If I press the AddNewItem again I get an exception
> because som required fields are not set.
>
> I tried using the Validating event on the required field bound controls
> but
> since the focus never gets to these controls, the validating procedure is
> never called.
>
> How can I make sure that all fields are valid before the bindingNavigator
> tries to write to the dataset?
>
> thanks
>
> Jeronimo Bertran
I had the exact problem, posted a message three days ago and received no
replies. In those three days I came up with something that works.
The only event that I could find that would fire before the row is attached
to the dataset was the MouseDown event on the Binding Navigator buttons.
So it looks something like this:
Private Sub Validate_Detail(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles _
BindingNavigatorAddNewItem.MouseDown, _
BindingNavigatorMoveFirstItem.MouseDown, _
BindingNavigatorMoveLastItem.MouseDown, _
BindingNavigatorMoveNextItem.MouseDown, _
TblTeamsBindingNavigatorSaveItem.MouseDown
Validate_Stuff()
End Sub
Private Sub BindingNavigatorPositionItem_Enter(ByVal sender As Object, ByVal
e As System.EventArgs) Handles _
BindingNavigatorPositionItem.Enter
Validate_Stuff()
End Sub
Private Sub Validate_Stuff()
If Me.TeamIDTextBox.Text = "" Then
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
MessageBox.Show("You have to fill in the team id", "Detail Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.TeamIDTextBox.Focus()
End If
End Sub
If you get an error and the MessageBox shows, the click events from the
BindingNavigator buttons do not fire.