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
When a type can be assigned null is called nullable, that means the type has no value. All Reference Types are nullable by default, e.g. String, and all ValueTypes are not, e.g. Int32. The Nullable < T > structure is using a value type as a nullable type. By default DateTime is not nullable because it is a Value Type, using the nullable operator introduced in C# 2, you can achieve this.
Using a question mark (?) after the type or using the generic style Nullable.
Nullable < DateTime > nullDateTime;
or
DateTime? nullDateTime = null;
More info...http://net-informations.com/q/faq/nullable.html
Crony
in C#, you define the date value as nullable:
DateTime? someDate;
make the conversion and validation of your data source
Then you assign the date value to the control,
if (someDate != null) dtSent.Value = someDate; else dtSent.Value = "";
DO NOT assign: dtSent.Value=null !!
The user get an empty control, where he.she can enter a date
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 :)
rlove@aecrepro.com