NullReferenceException Object reference not set to an instance of an object.
Source : MicroFour StrataFrame UI
Stack Trace: at MicroFour.StrataFrame.UI.Windows.Forms.DateTimePicker.CreateManualCaret() at MicroFour.StrataFrame.UI.Windows.Forms.DateTimePicker.OnGotFocus(EventArgs e) at System.Windows.Forms.Control.WmSetFocus(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.DateTimePicker.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m) at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
It appears about 3 times and then does blank out the date. Do you know why?
Set the column to nothing in the BO Mapper. Then drop a datetimepicker on the form, add a checkbox to it nd in the edit button click you can use something like the code below. Then you users will be able to null the field out if they want to. It looks pretty cool too.
I am using the Infragistics control but the SF control should work the same.
Michael
**********
Private Sub txtDateOfBirth_EditorButtonClick1(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinEditors.EditorButtonEventArgs) Handles txtDateOfBirth.EditorButtonClick Dim stateButton As StateEditorButton = CType(e.Button, StateEditorButton)
If (stateButton.Checked) Then e.Button.Editor.Value = Nothing Else e.Button.Editor.Value = DateTime.Today End If End Sub
new DateTime(1800, 1, 1)
in for the replacement value. When you access that field on the business object, it will return 1-1-1800 when the value in the database is Null and when you set the property to 1-1-1800, it will set the database to Null. Set the corresponding properties on the DateTimePicker, too, and it will display blank when the value is 1-1-1800.
There are lots of creative ways to handle Null dates in .NET because of the fact that a date is a value type, not a reference type. You could use the Nullable<DateTime> generic (DateTime?), or you could google it and find some solutions like CSLA's SmartDate class that handles it in a unique way.
The SQL Database has datetime columns that do allow null values. I do not want them to reflect 1/1/1800 or 1/1/1900. I want them to reflect NULL if they are null.
My question is what settings need to be made in the BO Mapping as well as the datetime picker control to make this work.
I am using c#.