Results 1 to 3 of 3

Thread: datetimepicker value is always true

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2021
    Posts
    13

    datetimepicker value is always true

    Hi,

    I've made a datetimepicker with a checkbox in it. Datetimepicker is intended as a filter - the user enters the date and gets filtered the data for that date. dtp is without binding.

    The problem is there, if the datetimepicker checkbox is empty, it still retains the value.
    Currently datetimepicker constantly feeds value to the database.

    So I thought, is that a validation problem or only the properties, but in my case I added checked = true and showcheckedbox = true also or need to looking somewhere else.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datetimepicker value is always true

    The Value property is type DateTime, so of course it always has a value. It's up to you to test the value of the Checked property and then use or don't use the Value property. It's not going to magic it for you.
    vb.net Code:
    1. If myDateTimePicker.Checked Then
    2.     'Use myDateTimePicker.Value here.
    3. Else
    4.     'Don't use myDateTimePicker.Value.
    5. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2021
    Posts
    13

    Re: datetimepicker value is always true

    Quote Originally Posted by jmcilhinney View Post
    The Value property is type DateTime, so of course it always has a value. It's up to you to test the value of the Checked property and then use or don't use the Value property. It's not going to magic it for you.
    vb.net Code:
    1. If myDateTimePicker.Checked Then
    2.     'Use myDateTimePicker.Value here.
    3. Else
    4.     'Don't use myDateTimePicker.Value.
    5. End If
    Thanks.
    Just figured it out, gave value as endDate and it worked.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width