I am using the Xceed DateTimePicker as the control in a wpf DataGrid for all columns that are bound to a Date property. Each of the those columns is defined as follows:
<DataGrid.Columns>
<DataGridTemplateColumn
Header="Charge Date"
Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Path=ChargeDate, StringFormat=yyyy-MM-dd, Converter={StaticResource conDate}}"
HorizontalAlignment="Center" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<tk:DateTimePicker Value="{Binding Path=ChargeDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
I don't think it is pertinent to my question, but for completeness sake, here is the styling for the pickers:
<Style TargetType="{x:Type tk:DateTimePicker}">
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Minimum" Value="2017-01-01" />
<Setter Property="DisplayDefaultValueOnEmptyText" Value="False" />
<Setter Property="ShowButtonSpinner" Value="False" />
<Setter Property="TimePickerVisibility" Value="Collapsed" />
<Setter Property="AutoCloseCalendar" Value="True" />
<Setter Property="Format" Value="Custom" />
<Setter Property="FormatString" Value="yyyy-MM-dd" />
</Style>
This works for datagrid cells that are already populated or when I am entering data in a new row. However when I click on an empty cell in an existing row, I get the following exception:
System.ArgumentOutOfRangeException: 'SelectedDate value is not valid.'
Why is the error only when I am enter data in an existing row? No code-behind is being executed when this exception happens so I don't know where to look for the problem.
Since you have set the
Minimum
property to2017-01-01
, you should also set the default value to the same date:You will get an
ArgumentOutOfRangeException
if the default value or value is less than the minimum value and this makes perfect sense.