Binding SmartDates

Binding SmartDates

Old forum URL: forums.lhotka.net/forums/t/2206.aspx


CrispinH posted on Thursday, January 25, 2007

I'm trying to bind a SmartDate using a BindingSource to a (nullable) DateTimePicker control using the Designer.  My ultimate objective is to have a date input control that will accept null dates ie the text is left blank or has words of your choice eg "Select" when the date is MinValue or MaxValue.  To this end I'm experimenting with Claudio Grazioli's Nullable DateTimePicker for CSLA.NET and the DevExpress DateEdit control.

 

The problem I’m having is actually getting the Date property of the SmartDate to bind with the control - I had expected it to ‘just work’ and I dragged the property from the Data Sources window onto the control.  In some respects it does work – the code generated by VS2005 is of the form:

 

Me.DateEdit1.DataBindings.Add(New System.Windows.Forms.Binding("EditValue", Me.MyBindingSource, "CourseStartDate.Date", True))

 

However this doesn’t work in practice and I’ve since heard that .NET DataBinding isn't going to work with a field in a structure.  I find it a bit odd that the designer accepts the structure in the first place, but that's a separate issue.  It's accepting the drag-drop data but putting a dot in the DataMember argument: this seems to be causing issues (but not exceptions) down the line.

 

How have other people solved the problem of binding SmartDates?  Is there a best-practice for this?

 

TIA

 

Crispin

DansDreams replied on Thursday, January 25, 2007

If you are exclusively using an input control that understands nulls, there's no reason for SmartDate any more IMO.  Using the DevExpress controls I just use DateTime? (C#), and I've never looked back.

 

CrispinH replied on Thursday, January 25, 2007

Dan

 

Thanks for the reply.  I was half-expecting to have to drop SmartDates so I’ll get on with that change now.  Even so, it would be interesting to know if anyone else had another approach.

 

Crispin

Copyright (c) Marimer LLC