WPF Telerik RadGridView - compare startDatePicker EndDatePicker and display error if there is one
I have the current code where 2 DatePicker are in a templeted cells of a RadGridView.
<telerik:RadGridView AutoExpandGroups="True" AutoGenerateColumns="False" ColumnWidth="Auto" HorizontalAlignment="Left"
ItemsSource="{Binding entries, Mode=TwoWay}" Name="gridControl1" VerticalAlignment="Top"
RowIndicatorVisibility="Collapsed">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Width="0.2*" DataFormatString="{}{0:M/yyyy}" Header="{my:LocString ResourceKey=EntitySheet_OwnerShip_DisplayStartDate}" SortingState="Ascending">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<DatePicker x:Name="StartDateTimePicker" SelectedValue="{Binding StartDate,Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True,UpdateSourceTrigger=LostFocus}"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Width="0.2*" Data开发者_运维问答FormatString="{}{0:M/yyyy}" Header="{my:LocString ResourceKey=EntitySheet_OwnerShip_DisplayEndDate}" SortingState="Ascending">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<DatePicker x:Name="StartDateTimePicker" SelectedValue="{Binding EndDate,Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True,UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PropertyChanged">
<cmd:EventToCommand Command="{Binding Path=ValidateStartDateCommand, Mode=OneWay}" CommandParameter="{Binding SelectedItem, ElementName=gridControl1}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadGridView>
I want to compare the startDate with the endDate and display an error if endDate < startDate when the focus is lost on one of the fields but no events is raised (event are raised on other columns). How I should do to raise an event permiting me to get the new values of the edited row and compare them?
Thank you in advance
Have you tried implementing the IDataErrorInfo interface on your ViewModel (assuming you are using MVVM) or whatever other class you are binding your datagrid to. Implementing that interface should allow you to write the validation code in the indexer to give you the desired results.
Hope this helps out a bit.
精彩评论