|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Date/Time Pickers/VB2005I'm building a database application that has a number of date fields in it.
When I add the date/time picker control to my form and run it, if the field is null in my db, then it shows the current date. How can I get this control to be blank when the corresponding field in my db is blank? Thanks! Darhl Darhl Thomason wrote:
> I'm building a database application that has a number of date fields in it. There is no built in support in the control for null dates. Here's> When I add the date/time picker control to my form and run it, if the field > is null in my db, then it shows the current date. How can I get this > control to be blank when the corresponding field in my db is blank? what I did: First I create two string to hold the date format. Note that the Not Specified string includes an apostrophe (') at each end. 'Not Specified' Dim _userCustomFormat As String = "MM/dd/yyyy" Dim _nullFormat As String = "'Not Specified'" On the DateTimePicker control, set the format to Custom Then in the code, check to see if the date is null (Nothing) and if so, us the _nullFormat, otherwise use your desired date format: If _dateVariable.HasValue Then dtpDate.Value = _currentEmployee.AgreementDate.Value dtpDate.CustomFormat = _userCustomFormat Else dtpDate.Value = DateTime.MinValue dtpDate.CustomFormat = _nullFormat End If Hope this gives you some ideas. Thanks Chris,
I know you're just making names up because you don't know my db, but I don't know how to pull the value of my date field. You're using "_dateVariable" and "_currentEmployee.AgreementDate" and I don't know where they come from...I'm assuming these are variables that get assigned somewhere. I get the concept of this, but am struggling with how/where to assign my values. Can I put this into a loop? I've got 6 dtp controls...so could I do something like: For Each dtp in frmStoreData if/then... else... endif... Next Darhl Show quoteHide quote "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1157663037.981340.80300@i3g2000cwc.googlegroups.com... > Darhl Thomason wrote: >> I'm building a database application that has a number of date fields in >> it. >> When I add the date/time picker control to my form and run it, if the >> field >> is null in my db, then it shows the current date. How can I get this >> control to be blank when the corresponding field in my db is blank? > > There is no built in support in the control for null dates. Here's > what I did: > > First I create two string to hold the date format. Note that the Not > Specified string includes an apostrophe (') at each end. 'Not > Specified' > > Dim _userCustomFormat As String = "MM/dd/yyyy" > Dim _nullFormat As String = "'Not Specified'" > > On the DateTimePicker control, set the format to Custom > > Then in the code, check to see if the date is null (Nothing) and if so, > us the _nullFormat, otherwise use your desired date format: > > If _dateVariable.HasValue Then > dtpDate.Value = _currentEmployee.AgreementDate.Value > dtpDate.CustomFormat = _userCustomFormat > Else > dtpDate.Value = DateTime.MinValue > dtpDate.CustomFormat = _nullFormat > End If > > Hope this gives you some ideas. > "Darhl Thomason" <darhlt@papamurphys.nospamplease.com> schrieb: Untested:> I'm building a database application that has a number of date fields in > it. When I add the date/time picker control to my form and run it, if the > field is null in my db, then it shows the current date. How can I get > this control to be blank when the corresponding field in my db is blank? <URL:http://www.grazioli.ch/Blog/PermaLink.aspx?guid=c4a63d35-71f9-4b02-9de7-0c87e5b1c770> Nullable DateTimePicker <URL:http://www.codeproject.com/cs/miscctrl/Nullable_DateTimePicker.asp> (For a translation to VB.NET, take a look at the comments section of the page.) You may want to set the 'ShowCheckBox' property to 'True' and use the checkbox as a null value indicator (if 'Checked' is 'False', no date is selected). Notice that the 'ShowCheckBox' property is flawed and thus this is not the best way. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Async socket connection ends up in Unable to read data from....
.NET Remoting & RTD Search for files in folders? Print out contents of a hashtable app.config not copied to bin directory Opening a space delimited textfile in Excel using VB.net entlib UpdateDataSet how to update the database? Download tif from the web via a stream with progress indication embedded text file how to receive data from .NET socket into VB6 winsock ? |
|||||||||||||||||||||||