You can’t bind a Windows Forms DateTimePicker to a field that might contain DBNull… so I did this;
public class DBDateTimePicker:DateTimePicker
// TODO: Add constructor logic here
public object DBValue
this.Value = Convert.ToDateTime(value);
Then I bind to “DBValue” (instead of Value) and it appears to work fine… if it is null, it is unchecked and disabled, otherwise it is enabled and can be set to any normal date value... if you uncheck the box yourself, then the data field is set to DBNull...
Not sure if it the best idea, but I can’t override Value so this seems like a reasonable alternative… of course, I never looked around for the "official" solution or any other possible answers, so let me know if you have a better idea!
Thoughts on this post? Feel free to reach out on Twitter!
2003-03-01 01:03 +0000
0b01fd9 @ 2019-02-21