Monday, September 22, 2014

DatePicker won't update source field

This really has nothing to do with date picker - it has to do with a retarded programmer - namely me.

I have a date picker (could be any control) with a selected date bound to a particular column in a particular datarow. I also have the following piece of code to initialize the date if it is empty in the datarow.

If ToDatePicker.SelectedDate is nothing then ToDatePicker.SelectedDate = today

That seems OK. It works, it displays today's date if the database field is DBNull. The problem is that when the user selects a different date, the source field is not updated.

Of course the smarter programmers have already seen the problem. I broke the binding so the DatePicker is no longer bound to the datarow. The correct solution is...

If Convert.IsDBNull(DR("to_date")) then DR("to_date") = today

This has to be one of the most difficult paradigm shifts required to be a good WPF programmer. It certainly has proved to be that way for me.

No comments:

Post a Comment