SmartDate in a grid.

SmartDate in a grid.

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


ThomasJGregg posted on Tuesday, July 17, 2007

I need to be able to have a dropdown date(calendar dropdown) in a grid column.  The user has the choice to choose a date or leave it blank.  I am not sure how to use the smartdate null ability with the dropdown in the grid.  To add the dropdown, I am doing the following:

DataColumn onsetDate = new DataColumn("OnsetDate", typeof(DateTime));

dataTable.Columns.Add(onsetDate);

But it doesn't like the DateTime with the SmartDate.

I am using CSLA 1.x.  Any help would be appreciated.

RockfordLhotka replied on Tuesday, July 17, 2007

SmartDate is specifically designed to allow your object to expose a String property, and a SmartDate field behind that property. Look at Chapter 7 of the 1.0 book for details on how to use it properly.

The reason for exposing the property as type string, is that string allows the user to enter an empty value, while DateTime never does. DateTime is a terrible type for data entry Sad [:(]

I'm not sure how to do a dropdown date picker in the grid - it depends on who's grid control you are using and how they handle it. But supporting a picker and a blank entry may be difficult, because so many control vendors follow the DateTime pattern that says the user can't leave the field blank. Lame, but true.

ajj3085 replied on Wednesday, July 18, 2007

RockfordLhotka:
But supporting a picker and a blank entry may be difficult, because so many control vendors follow the DateTime pattern that says the user can't leave the field blank. Lame, but true.


Yes, I've found it to be quite lame too.  I was able to subclass the standard DateTimePicker control though, and if you have the control show a checkbox, unchecking the box can mean "no date."  You need to subclass though to make checking the box set or clear the underlying value appropriately, as it doesn't do that correctly.  Searching with google will turn up several examples of this. 

Copyright (c) Marimer LLC