Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

Date Type Custom Format Provider?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
McNutt Consulting - 01 Sep 2004 16:23 GMT
All,

I have a class with a date field

<Serializable()> Public Class Account

   Private _startdate As Date
   Public Property StartDate() as Date
       Get
           return _startdate
       End Get
       Set(ByVal Value As Date)
           _startdate = Value
       End Set
   End Property

...class properties/methods

End Class

When this is bound to a datagrid, it shows 1/1/0001.  I understand why and
all the value type/reference type discussion I've read are clear.  However,
when _startdate.equals(date.minvalue), I don't want to display anything in
the datagrid or anywhere else for that matter.  I want StartDate.ToString to
return String.Empty.

Is this possible with a custom format provider or in any other way?

Thanks for you time,
Larry
Sijin Joseph - 01 Sep 2004 17:12 GMT
Hi Larry,

One option would be that when you do the databinding, you can handle the
format event of the binding object and convert DateTime.MinValue to an
empty string and in the Parse event of the binding you can convert empty
string to DateTime.MinValue.

One other option would be to write a new DateTime that encapsulates the
framework DateTime and exposes the same interface as DateTime, execpt
that the ToXXXString() methods would first check if the value ==
MinValue, and if so would return an empty string. This seems quite
tedious. Ofcourse it could have been easier if you could inherit from
DateTime.

Implementing a IFormatProvider would not help as far as i see, because
the UI controls never make use of this interface.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> All,
>
[quoted text clipped - 26 lines]
> Thanks for you time,
> Larry

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.