Solved

Avoid typing in Datepicker text

Posted on 2011-09-27
6
696 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now