Solved

Avoid typing in Datepicker text

Posted on 2011-09-27
6
711 Views
Last Modified: 2013-11-12
Hi All,
Advance thanks.
I am using Datepicker control in UI. Would need to restrict user only to select the date from the dropdown calender. Now when the user types in any characters in the text, it get stayed and i don't know how to clean the text. Is there any way to restrict the user not to type in anything in the text area.

Kind regards,
Pooja
0
Comment
Question by:poojasureshkumar
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 36711058
Cancel the key in the KeyPress event. Maybe add a beep so that the user as some feedback.

Private Sub DateTimePicker1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DateTimePicker1.KeyPress
   e.Handled = True
   Microsoft.VisualBasic.Beep()
End Sub

Open in new window

0
 

Author Closing Comment

by:poojasureshkumar
ID: 36711428
Excellent.
0
 

Author Comment

by:poojasureshkumar
ID: 36718538
Hi James,
It is working fine  for first time. I mean, it is disallowing the user not to type in anything in the  text first. But allow them to enter text after the date is picked from the calendar.

Kind regards,
Pooja
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 40
ID: 36718813
You added something somewhere.

Attached is a simple form that shows the concept, and they cannot type in even after making a selection. Form1.zip
0
 

Author Comment

by:poojasureshkumar
ID: 36720062
Hi James,
Am using SL4. This is my code

   Private Sub DateTimePicker_KeyPress(ByVal sender As Object, ByVal e As KeyEventArgs)
        If Not e.PlatformKeyCode = 9 Then e.Handled = True
    End Sub

Kind regards,
Pooja

0
 
LVL 40
ID: 36720448
The code would be the same.

If the keypress cancels everything except a tabulation (that is what the 9 stands for, isn't it?) before selecting a date, it should continue to do the same after.

If you put a breakpoint in the KeyPress, is it still hit after the selection?

If so, there is no reason why the code would not still work.

If not, then something broke the link between the event and the event procedure. I am sorry, but I do not know how the procedure is linked to the event in Silverlight.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question