943,945 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 6480
  • VB.NET RSS
Oct 9th, 2008
0

Disabling dates before current date of a datetimepicker control

Expand Post »
Hey Everyone

Is it possible to disable the dates that appear before todays date in a dateTimePicker control?

I want to put in some validation so that my users can only select days in the future...ie a future appointment date

Any ideas ?


Thanks
Reputation Points: 30
Solved Threads: 0
Junior Poster in Training
Elmo_loves_you is offline Offline
85 posts
since Mar 2008
Oct 9th, 2008
0

Re: Disabling dates before current date of a datetimepicker control

hey,
maybe this will be helpful...try something like (for validation)

if dtpkr.value < dtpkr.value.date then

display error

else

yourvariable = dtpkr.value

end if

sorry im a beginner to but i think this should work, Gd Lk
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hisheeraz is offline Offline
9 posts
since Oct 2008
Oct 9th, 2008
0

Re: Disabling dates before current date of a datetimepicker control

I'm not certain what version of Visual Studio you're using - I'm still using 2003 however we have purchased and installed 2008 and I am preparing to start using it in the next week or two..

however in 2003 in your toolbox you have the required field validator you can use - you set the validator to validate the date textbox or whatever you want and in the operator field of the properties you chose greater than or greater than equal if you want them to be able to enter todays date.

you can then insert a validation summary from the toolbox and in error message of your validator you can list the message you want to place in that summary area. So you can say "Date can not be prior to today" and it will tell them what's wrong. You can even insert a second validator and make it required so it will make sure it's also not blank and so on.

you can mess with settings like make the color red etc.

Then in your code you can put in a valid fields check - an example I've used for one of mine is here

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub ValidFields()
  2.  
  3. Dim strError As String = "Validating Request."
  4.  
  5. Try
  6.  
  7. cpvRequestedDueDate.ValueToCompare = DateTime.Now.Today.ToShortDateString
  8.  
  9. rfvReqUser.Validate()
  10. rfvTitle.Validate()
  11. rfvDescription.Validate()
  12. rfvPriority.Validate()
  13. cpvRequestedDueDate.Validate()
  14. cpvRequestedDueDate2.Validate()
  15. rqvDueDate.Validate()
  16.  
  17. Catch ex As SqlException
  18. PageUtil.ShortProcessErrors(ex, Session, Me, strError)
  19. PageUtil.ShowError(Page, strError)
  20. Catch ex As Exception
  21. PageUtil.ShortProcessErrors(ex, Session, Me, strError)
  22. PageUtil.ShowError(Page, strError)
  23. Finally
  24. End Try
  25.  
  26. End Sub

in the above example - rqvDueDate is one validator that was inserted to validate due date. That name was set in the id field of the properties.
Last edited by rapture; Oct 9th, 2008 at 12:37 pm.
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Nov 6th, 2009
0
Re: Disabling dates before current date of a datetimepicker control
am realy desperate guys i need the code to control users picking up unwanted date or time. thanx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SKARY is offline Offline
2 posts
since Nov 2009
Nov 6th, 2009
0
Re: Disabling dates before current date of a datetimepicker control
sorry, i forgot something. i am uing asp.net with vb
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SKARY is offline Offline
2 posts
since Nov 2009
Aug 10th, 2010
0
Re: Disabling dates before current date of a datetimepicker control
datetimepicker.mindate = now

this should do the trick
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jay200032 is offline Offline
11 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: VB.net : system build
Next Thread in VB.NET Forum Timeline: How to add music in VB.Net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC