I have an UltraComboEditor that is databound to a reference property on a single object. I have the Nullable property set to true on the UltraComboEditor. When I clear the text of the UltraComboEditor, it tries to set the underlying property value to DBNull instead of null. I thus get the ArgumentException: "Object of type 'System.DBNull' cannot be converted to type 'YNAB.Data.SubCategory'.". Is there a way to force the UltraComboEditor to use null instead of DBNull? If not, is there a way that I can tell the underlying code how to convert from DBNull to null? I tried making a custom TypeConverter, and all tried making an implicit conversion operator, and niether seem to work, although I certainly could be missing something obvious.
Many thanks for any help you can offer,
Taylor
Hi Taylor,
I think what you can do is use the Binding object. This is the object that is returned to you when you call DataBindings.Add on the control. The proprety you are looking for is DataSourceNullValue.
What if you are not binding the control? I have the same issue with the UltraNumericEditor but I am simply setting and getting the ctl.Value when I need it, no binding involved. I would much rather cast numEditor.Value to a nullable decimal than check if it is DBNull.Value then set accordingly.
Anything I can do about this? Thanks.
Hi Drew,
I'm afraid I'm not following you. If you are not binding the control, then the Value property will return whatever you set it to.
Are you saying that it returns DBNull.Value when the user clears out the text? If that's the case, then I don't think there's any way to change that. You would simply have to code it to handle DBNull and convert it to a Nullable decimal (or whatever you need).
Hi Mike. Thanks for your quick response.
Yes thats correct. When the user clears out the editor and I get the control value it is set to DBNull.Value. I was looking for something like a NullValue property which would act similar to the NullText property but for Value instead of Text value.
To handle this now we created a generic method to simply cast the input parameter to the given generic type argument but first check for DBNull.Value. This seems to work nicely but was wondering if there was some built in functionality to the control.
There's nothing built-in. I suppose you could use a DataFilter, but that's really no better or easier than just writing a method.
We probably should have some sort of NullBehavior property. You should Submit a feature request to Infragistics