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?
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?
Re: Need Help With Datagridview Default Error Dialog
No, the data is not bound. Its either typed in or pasted by the user.
1 Attachment(s)
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.
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 :/
Re: Need Help With Datagridview Default Error Dialog
Quote:
Originally Posted by
barnaby
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.
Re: Need Help With Datagridview Default Error Dialog
Quote:
Originally Posted by
barnaby
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 :-)
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.