Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings and thank you for your time.

I would like to explain what I'm trying to obtain and the steps I've followed to get to the problem.

1. Start New Visual Studio Project.
2. Add new DataSet.
3. Add a DataTable to the DataSet.
4. Add two Columns to DataTable1, with the following caracteristics:

Column1
Name: DataColumn1
AllowDBNull: false
DataType: System.DateTime

Column2
Name: DataColumn2
AllowDBNull: true
DataType: System.String

5. Create a new Windows Form.
6. Open de Data Sources window and locate DataSet1, with corresponding DataTable1.
7. Change the DataTable1 from DataGridView to Details.
8. Drag the detail table from the DataSources window onto Form1.

Here is where the problem begins:

Two controls are added, both databound, a DateTimePicker and a TextBox.

The value of the DateTimePicker control can't be null, therefore it must pass a value in order to be able to stay in DataSet1.

A BindingNavigator is also added that has the add button.

When the application is run, and the DateTimePicker's default value is changed to the current date, I click the add button and I get an error indicating that the value for DataColumn1 (DateTime) can't be null.

This indicates that I have to manually select the current Date in the DateTimePicker control in order to pass a value, but when I look at the Value property of the DateTimePicker, it already has a value, without having to select it.

I know I could assign that value to the new row begin added to the DataSet, but that would eliminate the whole purpose of databinding the controls to the dataset, would it not?

Is there something I am missing in order for this to work?


Thank you for your time, if you need more clarification, I'd be happy to respond.
Posted

1 solution

I remember looking for this myself a while back and I ended up using the code from this article.

http://windowsclient.net/blogs/faqs/archive/2006/05/18/what-is-the-proper-way-to-bind-nullable-datetime-property-to-datetimepicker.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900