binding nullable property

  • Thread starter Thread starter Marka83
  • Start date Start date
M

Marka83

I'm creating custom datetimepicker with nullable<datetime> property Value.
When I bind this control

Binding b = new Binding("Value", source, "some nullable property");
DatePicker.DataBindings.Add(b);

and start application it throws this exception

Invalid cast from 'System.DateTime' to 'System.Nullable`1[[System.DateTime,
mscorlib, Version=2.0.0.0, Culture=neutral ...

I've tried to define format() and parse() but it's of no use.

In this example i've used visual studio 2008 and source is result of linq to
sql query
 
Marka83 said:
I'm creating custom datetimepicker with nullable<datetime> property Value.
When I bind this control

Binding b = new Binding("Value", source, "some nullable property");
DatePicker.DataBindings.Add(b);

and start application it throws this exception

Invalid cast from 'System.DateTime' to 'System.Nullable`1[[System.DateTime,
mscorlib, Version=2.0.0.0, Culture=neutral ...

I've tried to define format() and parse() but it's of no use.

In this example i've used visual studio 2008 and source is result of linq to
sql query

My mistake.
I didn't set b.FormattingEnabled = true;
 
Back
Top