PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2012 [RESOLVED] Can you set DateTimePicker value to Blank?-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Can you set DateTimePicker value to Blank?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Resolved [RESOLVED] Can you set DateTimePicker value to Blank?

    Good day all,

    I have a DateTimePicker that set the column Lead Time on my DataSet Table.
    Since it is DateTimePicker, it drops down a calendar for user to choose.

    The thing is, my client ask if they can set the value to blank, if they have not decided on the date to input.
    I'm not sure if it can be done since the DateTimePicker forces user to choose a date.

    Please advise the best way to do this.
    Thanks

    Name:  Set LeadTime As Blank.jpg
Views: 176
Size:  18.3 KB

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,099

    Re: Can you set DateTimePicker value to Blank?

    The DateTimePicker has an optional CheckBox for the user to enable/disable it.

    Set the .ShowCheckBox property to True, and then when using the date read the .Checked property first - if it is False, treat the date as being empty (otherwise read the value as usual).


    edit: corrected boolean value! (see post below)
    Last edited by si_the_geek; Aug 5th, 2019 at 05:33 AM. Reason: oops, wrong boolean value!

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Can you set DateTimePicker value to Blank?

    Quote Originally Posted by si_the_geek View Post
    if it is True, treat the date as being empty (otherwise read the value as usual).
    I think that you meant that the other way around.

    Note that the Value property of the DateTimePicker is type DateTime, which is a value type and thus cannot be Nothing or "empty". If your date/time data is nullable then you can't bind it to the DateTimePicker for that reason. You need to move the data back and forth manually. Loading the data might look like this:
    vb.net Code:
    1. If myDataRow.IsNull("DateOfBirth") Then
    2.     dateOfBirthPicker.Value = Date.Today
    3.     dateOfBirthPicker.Checked = False
    4. Else
    5.     dateOfBirthPicker.Value = CDate(myDataRow("DateOfBirth"))
    6.     dateOfBirthPicker.Checked = True
    7. End If
    Saving the data might look like this:
    vb.net Code:
    1. myDataRow("DateOfBirth") = If(dateOfBirthPicker.Checked, dateOfBirthPicker.Value, CObj(DBNull.Value))

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: Can you set DateTimePicker value to Blank?

    Thank you, everyone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width