Results 1 to 8 of 8

Thread: [2008 Exp] DataGridView - NoNullAllowedException

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  4. #4

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [2008 Exp] DataGridView - NoNullAllowedException

    I have found a few similar posts around the traps but no solution.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.....



  7. #7

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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!

  8. #8

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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
  •  



Click Here to Expand Forum to Full Width