Solved

Avoid typing in Datepicker text

Posted on 2011-09-27
6
706 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - KeyPress Event 4 38
write xml in vb.net 2 32
Input parameteres to DragOver 2 20
Access/Visual Basic Question 3 25
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

860 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