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.
Mike,
Yes, I understand the struct, and that a variable declared as a DateTime data type carries a minimum value (1/1/0001) and not a DBNull per say, in much the same way that an Integer data type carries a default value of 0 (can’t say minimum because of negative numbers etc). The data source I am using is a simple class object, whose property declarations should be treated like any other sort of strongly typed data source.
What a control renders to the display is the result of whatever intelligence programmed into its Paint method. Looking at the Infragistics DateTime Editor, we see that it has a Null Text Property, that will cause such text to be displayed in the control whenever the Value Property is equal to Nothing.
And allow me to give Kudos for extending the Null Text property to your controls. A handy little feature that saves me from having to clutter forms with Labels. Something I been hoping to see in controls for a long time.
Now sure enough, when Nothing is passed to the Value of the DateTime Editor, a custom, non-date, character string is displayed in the control (Ta Daaa !).
Great. So I guess my question is, Is it too much to ask for the control to be smart enough to say “when the input to the Value property is less then a specified minimum date or Nothing, then display the NullText value or nothing, as the case may be. I believe that would make many people very happy.
Which brings me back to the original question. What is the purpose of the Nullable Property on the control? I can’t seem to get the control to manage Null/Nothing values very well.
Anyway, I picked up on your hint regarding an Object data type and added another property constructor to the class of that type, and bound your control to it, and now it appears to have the desired behavior. The pseudo property declaration looks like this:
Public Property IIssueDate() As Object Get If _IssueDate.Year = 1 Or _IssueDate.Year = 1753 Then Return Nothing Else Return _IssueDate End If End Get Set(ByVal value As Object) If CType(value, Date) = CDate("1/1/1753") Then value = CType("1/1/0001", Date) _IssueDate = CType(value, Date) End SetEnd Property
Hey Mike,
Ya know this is something that has been bugging me for ages. I am sure that it is quite common across many business process solutions, that there are requirements to have optional Date. For example, Project StartDate, ProjectEnd. A future date can always be entered into the StartDate if the process has yet to begin, but while the process is ongoing, we cannot have a value EndDate. Oddly enough, SQL Server has no problem handling this situation (ie passing null/nothing values to parameters with a Date data type).
This being the case, any Date Control aught to be able to handle whatever is considered to be a Null Date. In the .Net world, this value is 1/1/0001. Therefore, that portion of my Validation Layer that handles Date values, as well as the Data Access Layer that will pass such values to the database via ADO, have both been coded with respect to the Year 1 value. So everything is right, until I am compelled to use a date control on a front end. That’s the problem.
I think the Min/Max properties are right for Business Logic. preventing the user for entering a value that is outside a desired range. However, there must be some value that the control considers to be a Null Date, if not Year 1, then some other value assigned by the user. That would solve the problem quite nicely.
ps
It’s true, I could write the corrective code around the DataBinding Class, or in any of the Filters that you mentioned. However, I didn't want to write code every where, so doing it in the business class objects seemed the right thing to do. Do it there also corrected the display issue I was having with ultra grid columns that carried a grid column style of DateTime, which were also showing the Year 1 value instead of nothing.
I will post a link to this thread in a Feature Request
r.
roblove said:Great. So I guess my question is, Is it too much to ask for the control to be smart enough to say “when the input to the Value property is less then a specified minimum date or Nothing, then display the NullText value or nothing, as the case may be. I believe that would make many people very happy.
This is an interesting idea, but I'm not sure a property is the right way to implement it. If I understand correctly, you are saying that a property should be added to the control that allows you to specify that DateTime.MinValue should be treated as null and display the NullTextLabel. This is certainly possible (and even easy) to implement. But what if you don't want to use DateTime.MinValue. Support you want to use DateTime.MaxValue, instead. Or suppose you want to use both? Suppose you want to treat anything outside of the MinValue and MaxValue of the control as null?
You may be right about DateTime.MinValue, and I encourage you to Submit a feature request to Infragistics. But I think it would be better to implement something like this in a method rather than a property. That way, you could examine the value of the control and display whatever text you want in any situation. And in fact, functionality already exists to allow you to do this via a DrawFilter, CreationFilter, or DataFilter. This implementation requires mode code, but it's also infinitely more flexible.
roblove said:Which brings me back to the original question. What is the purpose of the Nullable Property on the control? I can’t seem to get the control to manage Null/Nothing values very well.
The Nullable property determines whether or not the control accepts nulls. This is basically there to allow you to prevent the user from leaving the control blank. Setting Nullable true means that the control will allow nulls - but nothing the control does will force a null into a data source that can't support them.
By the way, if you are Binding the control, the DataBinding class has Parse and Format events which you can use to intercept and modify the value as it is copied from the control to the data source and vice versa.