DateTimePicker Problem
-
I put a question about this control yesterday, but unfortunatelly i could not get a solution. So i change the flow of my program, but I still have one problem. the DateTimePicker.valuechanged event executes twice... I ask the other programmers here and not one knows why this control behives like this. So maybe someone have an answer. (searching the net i found two programmers that created new threads to resolve the problem, but that does not work for me, because I need the return from the "IsValid":confused: ). Code sample: bool b = true; //the code below does not work because the second time around the value still //the original value in memory if(((DateTimePicker)sender).Tag.ToString() == ((DateTimePicker)sender).Value.ToString()) return; this.Cursor = Cursors.WaitCursor; if(isValid(sender)) { tToDate.MinDate = tFromDate.Value; BindTimecard(tFromDate.Value,tToDate.Value); ((DateTimePicker)sender).Tag = ((DateTimePicker)sender).Value; } private bool IsValid(object sender, object r) { if(objdsIO.TimeCard.GetErrors().Length > 0) { string msg = "Please, Delete or Fix Records in Error, before Proceding!"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon = MessageBoxIcon.Error; MessageBox.Show(this,msg,"Error",button,icon); ((DateTimePicker)sender).ValueChanged -=new EventHandler(TimeDate_ValueChanged); ((DateTimePicker)sender).Value = DateTime.Parse(((DateTimePicker)sender).Tag.ToString()); ((DateTimePicker)sender).ValueChanged +=new EventHandler(TimeDate_ValueChanged); return false; } return true; } thank you for your help!