Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks for your answer..

I have used datetime Picker in a custom control for selecting dates. for which I have used 2 datetime pickers.
using the event valuechanged I wrote the code. please read it.

<code>private void dtp_ValueChanged(object sender, EventArgs e)
{
Control ctrl = (Control)sender;
if (ctrl.Focused)
{
StartDate = dtpStartDate.Value;
EndDate = dtpEndDate.Value;
SelectedDateRange = DateRange.Custom;
}
}</code>
Posted
Updated 27-Jun-11 22:11pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Jun-11 2:21am    
Tag it! WPF, Forms, ASP.NET or what?
--SA
Jineesh TR 28-Jun-11 6:25am    
I have edited the code above can anyone please check it.

Check up it the control is focusable. You can check up the property CanFocus. Now, is it focusable by Tab navigation (set the property TabStop to true).

There is another possibility which I did not check up; could you do this? Check ContainsFocus instead. If ContainsFocus is true and IsFocused is false, it means that the control is composite so only one of its child control gets focus. Sorry I cannot do it right now. If you have a problem to do it, please ask a question and notify me by commenting this answer — I'll check it up and explain the results for you.

—SA
 
Share this answer
 
Because the Focus property does not have anything to do with the date being selected or not: It indicates that the "User Input Focus" is with the control. I.e. that user input will go to that control, and no other. If you want this control to have the input focus, use the Control.Focus[^] method:
myDateTimePicker.Focus();
 
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