Groups | Blog | Home
all groups > dotnet ado.net > june 2007 >

dotnet ado.net : Cancelling addition of new row


scott
6/26/2007 5:28:12 PM
I have a simple Windows form bound to one SQL Server table using the
BindingSource control. I would like to use the BindingNavigator
control to navigate through records. One text box holds a required
field. When I click the AddNew button on the BindingNavigator, a new
record is added to the DataTable and all fields are cleared on the
form. If I happen to press the AddNew button again and the required
text field remains empty, a System.Data.NoNullAllowedException occurs.

How do I cancel the addition of the new row if the required field is
empty?

Thanks!
Scott Adams
BD
6/28/2007 8:09:45 PM
Disable the binding navigator and any other controls that may allow
additions or deletions while adding/editing a record.

I usually create two functions. EnableAddEdit and DisableAddEdit. The
only purpose of the functions is to set the gui control states depending
on the action being performed.

While adding/editing a record I only enable the Save and Cancel buttons,
and the data controls(textboxes, combo's, etc). Everything else is
disabled (binding navigator, other buttons, menus,etc.)

HTH

[quoted text, click to view]
AddThis Social Bookmark Button