How to...

J

Jacek Jurkowski

.... bind nullable control property to nullable value?
The simpliest scenario:

public class a
{
Nullable<DateTime> myDate = null;

public Nullable<DateTime> MyDate
{
get{return myDate;}
set{myDate = value;}
}
}

public class MyControl : UserControl
{
Nullable<DateTime> date = null;

public Nullable<DateTime> Date
{
get{return date;}
set{date = value;}
}
}

public class MyForm : Form
{
a class_a = new a();
MyControl my_control = new MyControl();

protected override void OnLoad(EventArgs e)
{
this.Controls.Add(my_control);
// Next line causes the error.
// "Cannot format the value to the desired type".
my_control.DataBindings.Add("Date",class_a,"MyDate");
}
}

What to do to allow such binding in the simpliest way?
 
P

Pavel Minaev

... bind nullable control property to nullable value?
The simpliest scenario:

public class a
{
    Nullable<DateTime> myDate = null;

    public Nullable<DateTime> MyDate
    {
        get{return myDate;}
        set{myDate = value;}
    }

}

public class MyControl : UserControl
{
    Nullable<DateTime> date = null;

    public Nullable<DateTime> Date
    {
        get{return date;}
        set{date = value;}
    }

}

public class MyForm : Form
{
        a class_a = new a();
        MyControl my_control = new MyControl();

        protected override void OnLoad(EventArgs e)
        {
            this.Controls.Add(my_control);
            // Next line causes the error.
            // "Cannot format the value to the desired type".
            my_control.DataBindings.Add("Date",class_a,"MyDate");
        }

}

What to do to allow such binding in the simpliest way?

I'm not 100% sure that it is possible, but try playing with
Binding.NullValue and Binding.DataSourceNullValue (the latter in
particular defaults to DBNull.Value rather than null, which may be the
cause of your troubles).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top