Reputation: 1503
I have set the objct of a class as the datasource of the CR. All the string fields appear in the Fields Explorer in the design alright. But what happen to the numeric or datetime fields? How do I bring them?
public class ClsOutDocket
{
public string RegistrationNo { get; set; }
public double? WeightIn { get; set; }
public DateTime? DateIn { get; set; }
public string TimeIn { get; set; }
}
Upvotes: 1
Views: 779
Reputation: 67090
Unfortunately CrystalReport does not support Nullable<T>
and both DateIn
and WeightIn
fields are nullables.
If it's applicable in your case what you can do is to publish two extra properties that map null
to a value, like this:
public double _WeightIn
{
get
{
if (WeightIn == null)
return Double.NaN;
return (double)WeightIn;
}
set
{
if (value == Double.NaN)
WeightIn = null;
else
WeightIn = value;
}
}
Of course this will make your class pretty "dirty" and unless you're using a model class to pass data to the report this may be a problem. You may consider to add this attribute to hide that property in the VS editor:
[EditorBrowsable(EditorBrowsableState.Never)]
Do not forget that CR will see the "fake null" value (Double.NaN
and DateTime.MinValue
) and because it doesn't know they're special values it'll use them as they are. If this is a problem (or you can't use a proper null value) then you'll need to change your reports to handle this special cases.
Upvotes: 3