binding nullable property

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
 
M

Marka83

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;
 

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