Results 1 to 8 of 8

Thread: Need Help With Datagridview Default Error Dialog

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    70

    Need Help With Datagridview Default Error Dialog

    I have a d.g.v. with two columns. One is set as date and the other is set as decimal. If there is a row and a number is typed in the decimal column, you can delete it and leave the cell empty. However, the program will not let me delete the contents of a date cell and leave it empty. It just gives me the default error dialog saying that I need to put the contents in proper date form and it doesn't let me leave it blank.

    How can I make it so that it allows me to leave the cell blank?

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Need Help With Datagridview Default Error Dialog

    1) The default error dialog will occur unless you handle the DataError event of the DataGridView.
    2) Normally you would handle the CellValidating event of the DataGridView. My question is: Are you binding this DataGridView?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    70

    Re: Need Help With Datagridview Default Error Dialog

    No, the data is not bound. Its either typed in or pasted by the user.

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Need Help With Datagridview Default Error Dialog

    The attached project done in VS2008 uses a custom DataGridView column called CalendarColumn which at first did not take into consideration Dbnull values so I tweaked it for this demo so that if a null value came to the InitializeEditingControl event it would change the value to today but you can easily change this behavior.

    Run the project, press the large button at the base of the form which will set the current row date to nothing. Now click on the cell and today's date will be the default. If you want different behavior simply study the code and change as you see fit.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    70

    Re: Need Help With Datagridview Default Error Dialog

    I tried looking at your code and still couldn't figure out a way to allow the cell to be blank. Thanks anyways for your help. Its just really weird that I can leave cells blank in the decimal column and not the date column :/

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Need Help With Datagridview Default Error Dialog

    Quote Originally Posted by barnaby View Post
    I tried looking at your code and still couldn't figure out a way to allow the cell to be blank. Thanks anyways for your help. Its just really weird that I can leave cells blank in the decimal column and not the date column :/
    It is all there for you all you need to do is determine how to implement the logic in your project.

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Need Help With Datagridview Default Error Dialog

    Quote Originally Posted by barnaby View Post
    Its just really weird that I can leave cells blank in the decimal column and not the date column :/
    Actually there are issues with binding a decimal to a control and leaving it blank similar to what you are having with the date which is documented on MSDN, good you have not tripped into it :-)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    70

    Re: Need Help With Datagridview Default Error Dialog

    Ok, one last question. Im a beginner so this may sound a bit silly, but is there any way to set the null value of a column to and empty string? Because i think that would solve my problem. But when i type in "" it put quotes in every column....


    YES I GOT IT! Rather that doing it through the form design i just programmed it (dgv.Columns(0).DefaultCellStyle.NullValue = "") and now it works. Thanks for answering all my questions.

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