|
-
Dec 13th, 2007, 04:50 AM
#1
[2008 Exp] DataGridView - NoNullAllowedException
Hi All,
I have a DGV that is bound to a Table (SQL CE).
The 'Date' field dosn't allow Nulls.
My problem is I get an unhandled error when I press the add new row ('+') in the BindingNavigator twice.
(can also occur when using the down arrow and not having valid data in the preceeding cell)
Obviously this condition is justified - I understand that; I just can figure out a way to either
validate the Date cell on cell exit for example, or catch the error in the BindingNavigators button event.
(This condition can be replicated using the shipped NorthWind DB - as the ID cannot be Null)
I have also coded up the DataSet's 'Partial Class' to no avail.
It seems the error is tied up in the 'System.Data.DataColumn' and I can't get into that.
Ideas?
Last edited by Bruce Fox; Dec 14th, 2007 at 05:34 AM.
-
Dec 13th, 2007, 05:00 AM
#2
Re: [2008 Exp] DataGridView - NoNullAllowedException
Wouldn't you handle the DataError event of the grid? Also, if the DataColumn doesn't allow nulls then setting it's DefaultValue would be an answer too.
-
Dec 13th, 2007, 05:13 AM
#3
Re: [2008 Exp] DataGridView - NoNullAllowedException
Hi jmcilhinney,
"Wouldn't you handle the DataError event of the grid?" - I tried, but I think the error is generated beyond the grid, if that makes sense.
".. setting it's DefaultValue would be an answer too" - Funny enough, I have done that, and it still fails. I appears that the default Date data is placed in the field, but when you next press add, it errors. It is as if the default data wasn't commited to the grid as it were.
Are you in a position to drop the Nothwind 'Customer' Table as DGV on a Form, and press the Add button twice - it demonstates my issue.
Last edited by Bruce Fox; Dec 13th, 2007 at 05:19 AM.
-
Dec 14th, 2007, 03:40 AM
#4
Re: [2008 Exp] DataGridView - NoNullAllowedException
I have found a few similar posts around the traps but no solution.
-
Dec 14th, 2007, 04:04 AM
#5
Re: [2008 Exp] DataGridView - NoNullAllowedException
I just did some quick testing and it does seem to be a tricky one. The exception stack trace shows no user code and there don't seem to be any obvious events that can help.
Without having tested anything, I think validating as field values were changed and enabling and disabling the Add New button as you go would work, but it would not be trivial code to do so.
-
Dec 14th, 2007, 05:22 AM
#6
Re: [2008 Exp] DataGridView - NoNullAllowedException
Thanks for confirming that jmcilhinney 
I (as you may know) moved from VB6. In VB6 I never used bound controls to a DB, I always coded the operations myself. That way I could always validate the data entered prior to commiting it.
I concur with the stack results, and that is what I found difficult to work around. As mentioned, others have had a similar issue - no resolution in sight.
I have tried to add a value to the last row when the add button is pressed(similar approach to a default), but the value gets added after the new row once its been added. I used the row count -1, but then it must get recalculated.....
-
Dec 14th, 2007, 05:30 AM
#7
Re: [2008 Exp] DataGridView - NoNullAllowedException
As you mention: I did try to disable the Add button the first time it's pressed, the idea being that it wouldn't be enabled again till the data was valid - this was one of my fist attempts.
The problem I had was I couldn't Enable = False the button!!
It just persisted, and was selectable. I then hid it, and realised that wasn't athletically pleasing. - anywhoo, back to the drawing board!
-
Dec 19th, 2007, 06:43 PM
#8
Re: [2008 Exp] DataGridView - NoNullAllowedException
Anyone in a simlar situation and found a solution?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|