I am using a doubleTextBox from Syncfusion. The Value is bound to a Property in a ViewModel class via
myDoubleTextBox.DataBindings.Add("BindableValue", mViewModel, "myProperty");
This works fine, however i want to be able to assign NULL
as well which should cause the DoubleTextBox
to show the value of its NullString
Property (means i want to exchange "double myProperty" for the nullable type "double?
myProperty"). I found some forum posts from 2007 which state that DoubleTextBoxes
support null values, but all examples that i found use outdated versions with Properties that don't exist anymore.
When i just try to bind NULL
to the BindableValue
of the Textbox
, the application crashes on calling myForm.Show()
with the following errormessage (caused by myProperty)
"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt" (meaning that the object reference does not point to the instance of an object).
Do you have any ideas? Thanks in advance!
I have tried the same with the Syncfusion DoubleTextBox and no exception is thrown in the reported case.
Here is the sample and code snippet for your reference.
class ViewModel
{
Form1 frm = new Form1();
Data data = new Data();
public ViewModel(Form1 _frm)
{
frm = _frm;
foreach (Control ctrl in frm.Controls)
if (ctrl is DoubleTextBox)
{
(ctrl as DoubleTextBox).AllowNull = true;
(ctrl as DoubleTextBox).DataBindings.Add("BindableValue", data, "Age");
}
frm.Show();
}
}
public class Data
{
private double? _age = null;
public double? Age
{
get { return _age; }
set { _age = value; }
}
}
Sample Link: http://www.syncfusion.com/uploads/user/directTrac/General/DoubleTextBox-Nullvalues1436415288.zip