Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one date time picker in my project.

in that i validate the choose day always be monday.

for that i written a code that is working fine.my code as follows;


private void dt_startweek_ValueChanged(object sender, EventArgs e)
       {
           //Validation Week Start day always be monday
           if (dt_startweek.Value.DayOfWeek != DayOfWeek.Monday)
           {
               MessageBox.Show("Please Select  MONDAY Only", "Monday Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
               //dt_startweek.Visible = true;
               return;
           }
       }


user select any other day other than the MONDAY message will shows Please Select MONDAY Only.

when user press ok button.the message pop will close, ok,that is correct.

but calendar(datetimepciker also closed);

i don't want to visible the datetimepicker (calendar) gets closed when press ok button in the message.

how can i do using c#.

it is windows appplication.
Posted
Updated 4-Feb-13 23:57pm
v2

In the handler, set
C#
DialogResult = DialogResult.None;
This will cancel the OK action.
You probably want this in a Click handler for your OK button, if the validation fails.
 
Share this answer
 
There are a couple of ways to do this ...

Nice and simple is to select the control and send it the down key ...
C#
dateTimePicker1.Select();
SendKeys.Send("%{DOWN}");

but there is always the faint danger that the sendkeys may go elsewhere if you have a "clicky" user.

Safer way is to send the message directly to the control
using System.Runtime.InteropServices;
...

C#
[DllImport("user32.dll", SetLastError = true)]
private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
const int WM_SYSKEYDOWN = 0x0104;
at the top of your class and then after your messagebox
SendMessage(dateTimePicker1.Handle, WM_SYSKEYDOWN, (int)Keys.Down, 0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900