Hi Alex,
You can do all your error-checking in your FormClosing event if you want to. Call a method to do the checking after you've done BindingSource.EndEdit(). If there are errors, then you'll obviously want to set e.Cancel = true and do nothing else.
Also, it's not a good idea at all to use user-entered fields for PKs!!! If possible, PKs should not contain meaningful data.
~~Bonnie
>Hi all,
> i have some difficult questions. i have a dataset( set a primary , b not null ) use databindings and one add, delete, save, exit buttion.
>Remark i use
>
>
> Private Sub Company_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
>
> Me.Validate()
> Me.CompanyBindingSource.EndEdit()
>
> If ADataSet.HasChanges(DataRowState.Added Or DataRowState.Deleted Or DataRowState.Modified) Then
> Dim drResult = New DialogResult()
>
> drResult = MessageBox.Show("Data updated, Do you want to save before program exit?", "Exit program", MessageBoxButtons.YesNoCancel)
>
> Select Case drResult
> Case DialogResult.Yes
> CompanyBindingNavigatorSaveItem_Click(sender, e)
> DataGridView1.Dispose()
> e.Cancel = True
> Case DialogResult.Cancel
> e.Cancel = True
> Case DialogResult.No
> e.Cancel = False
> DataGridView1.Dispose()
> End Select
> End If
>
> End Sub
>
>
>
>1. How can i check the user entry duplicate primary key , pop msg?
>2. If the user entry true primary key, but no entry b field, after he use BindingNavigator go to other position, how to check the b field not null
>3. How to check user press exit , then closing the form ,if primary key duplicate also colsing, no check him ?
>4. i have a datagirdview, the user entry the primary key but b field no entry , how to check him after he press save or add button ,
> and focus to null cell .
>
>Anyone can give some idea , i already find some days in internet but no information...... thank thank thank