This question is locked. New answers and comments are not allowed.
Greetings,
Due to the nature of work, we have a RadGridview which holds on datetime column. When a value of that column is Minvalue (1/1/0001) then we show blank.
In the Edit Mode, it is allowed to have a blank date value but we got the error.
We are using resource to control it as follow:
in our .xaml file, we have a column defined as:
In our .xaml.cs file, we have this function to allow the blank Datetime value:
However, when we run the app, and blank is given at that Datetime value, the error shows as followed:
http://i12.photobucket.com/albums/a201/le9569/1-6.jpg
Am I missing something? I have noticed that when a blank value is called, it calls the Convertback function in the
Help is appreciated.
John.
Due to the nature of work, we have a RadGridview which holds on datetime column. When a value of that column is Minvalue (1/1/0001) then we show blank.
In the Edit Mode, it is allowed to have a blank date value but we got the error.
We are using resource to control it as follow:
public class NullableDateFormatter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var dt = (Nullable<DateTime>)value; if (dt != null && dt.HasValue && !dt.Equals(new DateTime())) return dt; return string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //string strValue = value as string; //DateTime resultDateTime; //if (DateTime.TryParse(strValue, out resultDateTime)) // return resultDateTime; //return DependencyProperty.UnsetValue; return null; }}in our .xaml file, we have a column defined as:
....RowEditEnded="dgPhasesEdit_RowEditEnded"CellValidating="dgPhasesEdit_CellValidating"......<telerik:GridViewDataColumn Header="Acceptance Needed" DataMemberBinding="{Binding Acceptance_Needed_Date, StringFormat='M/dd/yyyy', Converter={StaticResource nullableDateFormatter}}" Width="*"> <telerik:GridViewDataColumn.CellStyle> <Style TargetType="telerik:GridViewCell"> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> </telerik:GridViewDataColumn.CellStyle></telerik:GridViewDataColumn>In our .xaml.cs file, we have this function to allow the blank Datetime value:
private void dgPhasesEdit_CellValidating(object sender, GridViewCellValidatingEventArgs e){ if (e.Cell.Column.UniqueName.Equals("Acceptance_Needed_Date")) { object newValue = e.NewValue; if (newValue == null) //Allow the null/blank Date value return; if (!Helper.IsDateTime(newValue)) { e.IsValid = false; e.ErrorMessage = "Invalid DateTime format"; } }}However, when we run the app, and blank is given at that Datetime value, the error shows as followed:
http://i12.photobucket.com/albums/a201/le9569/1-6.jpg
Am I missing something? I have noticed that when a blank value is called, it calls the Convertback function in the
NullableDateFormatter class.Help is appreciated.
John.