Disabling dates before current date of a datetimepicker control

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Disabling dates before current date of a datetimepicker control

 
0
  #1
Oct 9th, 2008
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
Michelle (Junior Developer)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 9
Reputation: hisheeraz is an unknown quantity at this point 
Solved Threads: 0
hisheeraz hisheeraz is offline Offline
Newbie Poster

Re: Disabling dates before current date of a datetimepicker control

 
0
  #2
Oct 9th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

Re: Disabling dates before current date of a datetimepicker control

 
0
  #3
Oct 9th, 2008
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: SKARY is an unknown quantity at this point 
Solved Threads: 0
SKARY SKARY is offline Offline
Newbie Poster
 
0
  #4
17 Days Ago
am realy desperate guys i need the code to control users picking up unwanted date or time. thanx
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: SKARY is an unknown quantity at this point 
Solved Threads: 0
SKARY SKARY is offline Offline
Newbie Poster
 
0
  #5
17 Days Ago
sorry, i forgot something. i am uing asp.net with vb
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC