Handle Unsupported Values
There are cases where an editor might not support some values from your data source. A good example of this is if when you have a DateTime field in your data and this field contains a record with DBNull value. RadDataEntry will resolve the field type to DateTime and will create a RadDateTimePicker editor for it, however, since it does not support displaying DBNull value as data, it does not know how to handle it and the simple data binding will fail.
To handle this case, you need to tell the RadDateTimePicker, how to interpret this value. This can be done by using the Format event of the binding.
The following example demonstrates how to do that:
1. In the BindingCreating event of the control you can tell which property to bind the field to. Here you should bind the "DateTime" field from the data source to the "NullableValue" property of RadDateTimePicker (as it supports null values).
Map Nullable Property
void radDataEntry1_BindingCreating(object sender, BindingCreatingEventArgs e)
{
if (e.DataMember == "DateTime")
{
e.PropertyName = "NullableValue";
}
}
2. Then in the BindingCreated event you will enable the binding formatting and will subscribe to its Format event.
Enable Formatting
void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
{
if (e.DataMember == "DateTime")
{
e.Binding.FormattingEnabled = true;
e.Binding.Format += Binding_Format;
}
}
3. At the end we just need to interpret the DBNull values as null values:
Evaluate DBNull
void Binding_Format(object sender, ConvertEventArgs e)
{
if (e.Value.Equals(DBNull.Value))
{
e.Value = null;
}
}