Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi
 
I have a form with three date picker controls. How can I validate that a user has actually selected a date (even if it is today). The dates will typically fall within range of about a month before to a month after the current date.
 
Thanks
 
R
Posted 31-Jan-13 7:05am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When you use a DateTimePicker control, they always show a valid date time - that's the whole point. They never show or return an invalid date.
 
If you need to know that the user has changed it (or changed it and changed it back) then handle the ValueChanged event.
  Permalink  
Comments
Richard.Berry100 at 31-Jan-13 12:31pm
   
Oops my bad - I did not expect that the ValueChanged event would fire if you selected the current date. If they are selecting Today's date, I need to know that they intentionally chose Today's date, and did not forget to select the date - if that makes sense. I realize the date will always be a valid date. Thanks for the reply!
OriginalGriff at 31-Jan-13 13:56pm
   
You're welcome!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

' Hello
 
' You can create a string like
Dim strDate as string
 
'Do something like this (sorry but i dont know the command from my head)
strDate = YourDateTimePicker.SelectedDate.ToString()
 
' Validation:
If strDate.Length > 0 then
'the user has selected a date
'you can continiue
Else
'he didnt select a date
'punish him!
End If
 
Hope it helped you a bit Smile | :)
  Permalink  
Comments
Richard.Berry100 at 31-Jan-13 12:37pm
   
Thanks for your answer - see my comment to OriginalGriff's answer. That way I can make sure they clicked the date - even if it is today's date

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 270
1 OriginalGriff 184
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Sergey Alexandrovich Kryukov 125
0 OriginalGriff 7,760
1 DamithSL 5,874
2 Sergey Alexandrovich Kryukov 5,444
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100