Reputation: 2249
I noticed that C#'s DateTimePicker is changing the date automatically when I'm changing Month or Year. So what I did is to override the ValueChanged and it is only fired when the CloseUp event is raised.
The problem now is I need an event if the user actually selected date in the calendar or the user clicks outside of the control.
Can you help me with this? Thanks :)
Upvotes: 2
Views: 11704
Reputation: 71
Upvotes: 0
Reputation: 11
In a derived class, the overriden OnCloseUp
method works because when you reset the datetime control, the ValueChange
event does not fire, so the CloseUp
event comes in handy.
void ProductionDateSchdl_CloseUp(object sender, EventArgs e)
{
this.ProductionDateSchdl.CustomFormat = "MM/dd/yyyy";
ProductionDate = Convert.ToDateTime(this.ProductionDateSchdl.Value);
}
Upvotes: 1
Reputation: 156
In a derived class, the overriden OnValueChanged
method works for me well.
public class MyDateTimePicker : DateTimePicker
{
// ... some stuff
protected override void OnValueChanged(EventArgs eventargs)
{
System.Diagnostics.Debug.Write("Clicked - ");
System.Diagnostics.Debug.WriteLine(this.Value);
base.OnValueChanged(eventargs);
}
protected override void OnCloseUp(EventArgs eventargs)
{
System.Diagnostics.Debug.Write("Closed - ");
System.Diagnostics.Debug.WriteLine(this.Value);
base.OnCloseUp(eventargs);
}
// some more stuff ...
}
Upvotes: 1