Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

DateTimePicker - Disable user from using arrow keys?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Artie - 21 Feb 2008 14:33 GMT
Hi,

I want to force the user to only use the drop down and calendar to
select a date in the DatetimePicker control.

I do NOT want them to select the control, then use the up and down
arrow keys to change the date.

How can I prevent them using the arrow keys?

Any help much appreciated.

Cheers

Artie
Alcides - 21 Feb 2008 15:17 GMT
You can try to handle the key down event and discard any keys you
want. Look at this code. Create a form and add datetimepicker control.
HTH.

Alcides Schulz.(http://alsql.blogspot.com).

   public partial class TestDatePicker : Form
   {
       public TestDatePicker()
       {
           InitializeComponent();
           dateTimePicker1.KeyDown += new
KeyEventHandler(event_KeyDown);
       }

       private void event_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
       {
           Console.WriteLine("KeyDown=" + e.KeyCode.ToString());
           if (e.KeyCode.ToString() == "Down" || e.KeyCode.ToString()
== "Up")
           {
               e.SuppressKeyPress = true;
               return;
           }

       }
   }
Franck - 21 Feb 2008 16:10 GMT
private void dateTimePicker1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{

if (e.KeyCode.ToString() == "Down" || e.KeyCode.ToString() == "Up")
{
e.Cancel;
}

}
Artie - 21 Feb 2008 16:50 GMT
> You can try to handle the key down event and discard any keys you
> want. Look at this code. Create a form and add datetimepicker control.
[quoted text clipped - 24 lines]
>         }
>     }

Thanks for your response Alcides.

I'd got one of the Event Handlers, but not the other.

So now I'm implementing the KeyDown and KeyPress event handlers and
doing "e.Handled = true" in each one.

Thanks again.

Artie
Claes Bergefall - 22 Feb 2008 10:29 GMT
<snip>
>            if (e.KeyCode.ToString() == "Down" || e.KeyCode.ToString() ==
> "Up")

if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)

  /claes

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.