bound datetime fields and clearing them

Posts   
 
    
jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 02-Aug-2005 21:58:55   

OK this one may be a little harder to explain. I have searched and seen a few posts on datetime handling, but I don't think any pertain.

If I have an infragistics datetime control bound to a datetime property on an entity, how do I clear the infragistics box and have it set the value to a null in the db? Right now, when the boxs is cleared, it tries to send a dbnull/nothing value back to the datetime property which it can't do since the datetime doesn't allow a null. The result is that the end user can't leave the box until he types a date.

If I change the box to return a datetime.minvalue it works fine at the ui level, but when the entity tries to save itself, since the field changes from a valid date to minvalue, llbl sends 1/1/1 to the db which blows up. Is there any better way to do this or make llbl send a null when it sees the minvalue?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Aug-2005 10:39:26   

Whatever is chosen, it's not optimal. That said, often users choose to hook up some code to the cell changed event handler so they set the actual value in the entity to null using SetNewFieldValue. This will result in the grid as Datatime.Minvalue (which is the default value), which you can then mask out in the grid as 'don't display'.

the other way is to pre-process entities before they're saved, for example in a Validator: in there, Datetime.Minvalue values are changed into null values (if the field is changed!) which then results in NULL values in the db.

Frans Bouma | Lead developer LLBLGen Pro