Search code examples
c#wpftelerik-grid

WPF RadGridView Default Date Value to Empty Value


How to override telerik radgridview's default date value (1/1/1900) to empty in xaml

xaml binding is like :

<telerik:GridViewDataColumn  Header="Estimated Start On" DataMemberBinding="{Binding EstdStartDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat=N2}"   Width="100"  IsFilterable="False" IsGroupable="False">
    <telerik:GridViewDataColumn.CellTemplate>
             <DataTemplate>
                 <Label Content="{Binding EstdStartDate}" Height="30"    />
             </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

Thanks, Sarathi


Solution

  • Take a look on how to implement WPF Value Converters.

    VIEW:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding DateColumn, Converter={StaticResource MyDateConverter}" IsReadOnly="True">
    

    CONVERTER:

    public class MyDateConverter:IValueConverter  
    {  
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
        {  
            if (value is DateTime)
            {
                DateTime test = (DateTime) value;
                if (test.Year > 1900) // If year is greater than 1900 then display
                {
                    string date = test.ToString("d/M/yyyy"); // Your date format
                    return date;
                }
            }
    
            return string.Empty;
        }  
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
        {  
            throw new NotImplementedException();  
        }  
    }