Inserts in DataGridView, then change your mind...

SteveInBeloit

Well-known member
Joined
May 22, 2006
Messages
132
Programming Experience
10+
I have a DGV, all works OK, but.

If I hit the "+" (add) button on the Navigator bar, it gives me the new row. But if I change my mind and do not want to add, as soon as I click on another row I get an exception flagging the first column in the table that doesn't allow nulls. Is there a way the it will not try to do the insert if I don't enter anything?

Thanks
 
make a new button on the navigator bar..

do a bindsource.canceledit()

whenever u change ur mind click that button
 
The problem you will face is that moving to another row in the grid implicitly calls EndEdit, thereby giving rise to the exception. See if there is an event you can hook to BEFORE the DGV causes an EndEdit (it will probably have a name ending with ING, like CurrentRowChanging or CurrentItemChanging), investigate if the PK is null, and if it is, assume that the user meant to cancel the entry.. Call CancelEdit at this time.

You can get really clever if they typed in other columns andyou want to help them preserve that :)
 
Back
Top