Date/Time Pickers/VB2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darhl Thomason

    #1

    Date/Time Pickers/VB2005

    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?

    Thanks!

    Darhl


  • Chris Dunaway

    #2
    Re: Date/Time Pickers/VB2005

    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 _userCustomForm at 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.H asValue Then
    dtpDate.Value = _currentEmploye e.AgreementDate .Value
    dtpDate.CustomF ormat = _userCustomForm at
    Else
    dtpDate.Value = DateTime.MinVal ue
    dtpDate.CustomF ormat = _nullFormat
    End If

    Hope this gives you some ideas.

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Date/Time Pickers/VB2005

      "Darhl Thomason" <darhlt@papamur phys.nospamplea se.comschrieb:
      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?
      Untested:

      <URL:http://www.grazioli.ch/Blog/PermaLink.aspx? guid=c4a63d35-71f9-4b02-9de7-0c87e5b1c770>

      Nullable DateTimePicker
      <URL:http://www.codeproject .com/cs/miscctrl/Nullable_DateTi mePicker.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/>

      Comment

      • Darhl Thomason

        #4
        Re: Date/Time Pickers/VB2005

        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 "_dateVaria ble"
        and "_currentEmploy ee.AgreementDat e" 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


        "Chris Dunaway" <dunawayc@gmail .comwrote in message
        news:1157663037 .981340.80300@i 3g2000cwc.googl egroups.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 _userCustomForm at 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.H asValue Then
        dtpDate.Value = _currentEmploye e.AgreementDate .Value
        dtpDate.CustomF ormat = _userCustomForm at
        Else
        dtpDate.Value = DateTime.MinVal ue
        dtpDate.CustomF ormat = _nullFormat
        End If
        >
        Hope this gives you some ideas.
        >

        Comment

        Working...