What is the purpose of the Nullable property. Regardless if it is set to True, the MinDate Property cannot be Null or Nothing and the DateTime Property cannot be Null or Nothing. So, how do you get the control to display nothing when the data field is Nullable and the current record has a Null value.
regards,
Rob
Hi Rob,
If Nullable is true, then the control should allow you to blank out the Value property. The DateTime property cannot be null, because it's of type DateTime, which is a struct and does not support nulls.
Hi Mike,
I kept getting the error " value cannot be set outside the range of the min/max value . . ." something like that. I found the problem was comming from the fact that the application is using business object class, where a null datetime property will carry a value of "1/1/001 12:00:00 AM" which, if I am not mistaken, is different the Infragistics minimum value for this datatype,
Anyway, I corrected the problem by putting a check for Year on in the code that loads the data into form controls.
If myClass.RevisionDate.Date.Year = 1 Then
myDateControl.Value=Nothing
Else
myDateControl.Value= MyClass.RevisionDate
End If
I could have put the code in the Class property declaration itself, but then the class cause problems elsewhere accross the solution.
Regards,
Well, I thought I had it beat.
Turn out, after trying to implement data bindings on the business class object, problems re-emerged. To correct, I had to implement corrective code in the class date property constructor as follows. . .
Private _RevisionDate as Date
Public Property RevisionDate() as DateGet If _RevisionDate.Year=1 Then Return CDate(“1/1/1753”) Else Return _RevisionDate End IFEnd GetSet(ByVal value as Date) If value = CDate(“1/1/1753”) Then value = Nothing _RevisionDate = valueEnd SetEnd Property
Then, after setting the form data bindings on the controls to the business class object, I still had to force a Null value into the date control, like . . .
If CType(Me.RevisionDate.Value, Date) = CType("1/1/1753 12:00:00 AM", Date) Then _Me.RevisionDate.Value = Nothing
And the control is still not correct, as it does not allow the user to enter and then leave without setting a valid date value. So am I missing something here?
Regards,Rob
It sounds to me like the problem is your data source, not the DateTimeEditor. As I said, a DateTime variable in DotNet cannot hold a null value. It's a struct. 1/1/0001 is the minimum date, but it's not the same as a null. If you need to store DBNull or Null in your data source, then it needs to be n object type. Or else you will need to use a DataFilter to convert the null into MinDate and vice versa.
Just curious what your thoughts are for new nullable types.
Given the following is valid: DateTime? myDate = null;What can be done to allow this type of datavalue in the control/datasource?
I'm not sure exactly how this should function in the UltraDateTimeEditor, but I found this topic by searching around for information regarding UltraGrid and nullable types.
In my issue, I've got a grid with certain columns (with ValueLists) that need to be blank(null) before the user configures them, then also must be able to be defaulted back to the null state at the user's discretion .. I won't go into this anymore in this topic as i'm still looking around for more information before I ultimately post another topic/find a solution -- but you happened to touch on the nullable idea, and just thought you might have some clues. The main reason why i see the Nullable enum to be an issue, is that you can't explicitly define any type as the nullable type, and are restricted to a select few.
rlove@aecrepro.com
The control does handle null dates by the way.
Your domain class would need to define the date as nullable "DateTime?" I also databind this just fine.
It's late but just FYI
Rob,
Thanks for your response -- i believe i've come to a suitable solution -- i've overviewed this here .
I know exactly what you mean about using the grid as an editor -- sometimes it just becomes a huge mess. However, with the requirements for the project i'm doing, a grid is required, and really the best choice. Furthermore, simply re-binding a modified datasource would create an annoying user experience in my case.
That being said, The solution I've come across does deal with the null values better. Conveniently, .NET does support nullable types (using the '?' at the end of the type declaration). However, using these nullable types causes an issue in some of hte underlying codebase of the Infragistics control, i believe -- at least as it pertains to DropDownListValidated styles on the ValueLists inside a grid. (i get exceptions when the grid is trying to compare a value to make sure it is 'valid'). You can see my 'temporary' solution in the post I linked above.
What was specifically happening to me was that inside the cell which was associated with a ValueList, A value could be selected from the list, but it was then impossible to clear the value. The first item in the list was always a null instance of my nullable enum, but even selecting the item from the list would not work, and would yield 'the data in the field is not valid' popup. If the user pressed Delete while in the field, the grid poped up a JIT Debugger error window, which was caused by the internal DropDownListValidate behavior.
Also, just to clarify, DBNull does not translate to Nothing (C# null) ;-) and this, i think, was the basis of my issue.
Back to the issue of the null value in the DateTimeEditor ... i would expect that if your datasource for the control was a property described as: DateTime? myDateTime = null;the control would be able to deal with this, and instead of using System.DBNull as a default null type, use either a configured null type (in the UltraGrid this is the Nullable property, which gives a few options), or be able to specify your own specific null value.
This way, you can avoid having to deal with the minimum date, and simply go with something like if (myDateTime.HasValue) { } else { }. One thing, however, is how does the user set the date back to 'null', to which I don not know the answer.
Hope that helps :)