This question is locked. New answers and comments are not allowed.
As long as I pick a time from the dropdown, everything works OK, but in the RowValidating event, if I type a time directly into the textbox and then click on another row, the e.Row.DataContext still has the old value. However, if I tab to the next column, the value is updated.
I think this is a bug. The DataContext should update, no matter how you exit the cell, prior to the RowValidating event.
So, to give you a specific example, here is my RowValidating code:
If I edit a row with an 11:00 AM start time and a 1:00 PM end time, changing the end time to 11:01 PM, I should get an error message since the elapsed time is greater than 12 hours, but if I exit the end time field by clicking on another row in the same column, the end time in the DataContext is still 1:00 PM and no error is triggered. If I come back to the row to edit it again, the DataContext and the underlying binding have the new invalid time, 11:01 PM.
How can I resolve this problem?
Thanks,
Terry
I think this is a bug. The DataContext should update, no matter how you exit the cell, prior to the RowValidating event.
So, to give you a specific example, here is my RowValidating code:
| private void gvTimeSheet_RowValidating( object sender, GridViewRowValidatingEventArgs e ) |
| { |
| ChargeInfo chg = e.Row.DataContext as ChargeInfo; |
| // require end time > starttime and <= 12 hours |
| // OK to roll over to next day |
| TimeSpan ts = chg.EndTimeSpan - chg.StartTimeSpan; |
| if ( ts == new TimeSpan( 0, 0, 0 ) ) |
| { |
| MessageBox.Show( "Start time cannot equal end time" ); |
| e.IsValid = false; |
| return; |
| } |
| else if ( ts < new TimeSpan( -12, 0, 0 ) || ts > new TimeSpan( 12, 0, 0 ) ) |
| { |
| MessageBox.Show( "Individual time charges > 12 hours are not allowed." ); |
| e.IsValid = false; |
| return; |
| } |
| } |
If I edit a row with an 11:00 AM start time and a 1:00 PM end time, changing the end time to 11:01 PM, I should get an error message since the elapsed time is greater than 12 hours, but if I exit the end time field by clicking on another row in the same column, the end time in the DataContext is still 1:00 PM and no error is triggered. If I come back to the row to edit it again, the DataContext and the underlying binding have the new invalid time, 11:01 PM.
How can I resolve this problem?
Thanks,
Terry