When altering the celltemplate on a GridViewDataColumn, I do not get the expected values in GridViewCellValidatatingEventArgs in the CellValidating event.
My XAML looks like something this:
<telerik:RadGridView Name="dayDriveLogGridView"
ItemsSource="{Binding DriveLog}"
AutoGenerateColumns="False"
Deleting="dayDriveLogGridView_Deleting"
CellValidating="dayDriveLogGridView_CellValidating"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Name="colKilometers"
SortingState="Ascending"
DataMemberBinding="{Binding Path=Entity.Kilometers}"
CellStyle="{StaticResource DisableIfNotSettled}"
>
<telerik:GridViewDataColumn.Header>
<TextBlock Text="{localView:Translate Kilometers}" ToolTip="{localView:Translate DriveLogTooltip}" />
</telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Name="colDestination"
IsReadOnly="False"
DataMemberBinding="{Binding Entity.Destination, Mode=TwoWay}"
CellStyle="{StaticResource DisableIfNotSettled}"
>
<telerik:GridViewDataColumn.Header>
<TextBlock Text="{localView:Translate Destination}" ToolTip="{localView:Translate DriveLogTooltip}" />
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<ComboBox x:Name="destinationComboBox" ItemsSource="{Binding Path=PossibleDestinations}" IsEditable="True"
LostFocus="DestinationComboBox_LostFocus"
SelectedItem="{Binding Path=Entity.Destination,
Mode=TwoWay}"
>
<ComboBox.Text>
<Binding Path="Entity.Destination" Mode="TwoWay"
>
<Binding.ValidationRules>
<model:DestinationValidationRule ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</ComboBox.Text>
</ComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Question 1: In dayDriveLogGridView_CellValidating, I get the expected e.NewValue when changing Kilometers, but not when changing Destination (whenever I input any string, e.NewValue is still null). I'd like to handle all my validations the same way in the codebehind... but it seems like I have to dig out Destination from the EditingElement ???
Question 2: It seems like the DestinationValidationRule gets activated and gives the combobox a red border. But for some reason, this does not bubble out, making the cell invalidated. Can this be done elegantly in XAML? Or in the code-behind.
To me, it seems like that in order to make validation, I need a way to hook the cell up with the combobox (either the rule or the cellvalidation) go most smoothly. Did I miss something?
(I did read http://www.telerik.com/help/wpf/gridview-managing-data-validation.html )
The viewmodel has a property called DriveLog. DriveLog is an observable collections of DriveLogEntryViewModel - each with the property Entry of type DriveLogEntry. DrivLogEntry is a Linq2SQL entity (autogenerated).
My XAML looks like something this:
<telerik:RadGridView Name="dayDriveLogGridView"
ItemsSource="{Binding DriveLog}"
AutoGenerateColumns="False"
Deleting="dayDriveLogGridView_Deleting"
CellValidating="dayDriveLogGridView_CellValidating"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Name="colKilometers"
SortingState="Ascending"
DataMemberBinding="{Binding Path=Entity.Kilometers}"
CellStyle="{StaticResource DisableIfNotSettled}"
>
<telerik:GridViewDataColumn.Header>
<TextBlock Text="{localView:Translate Kilometers}" ToolTip="{localView:Translate DriveLogTooltip}" />
</telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Name="colDestination"
IsReadOnly="False"
DataMemberBinding="{Binding Entity.Destination, Mode=TwoWay}"
CellStyle="{StaticResource DisableIfNotSettled}"
>
<telerik:GridViewDataColumn.Header>
<TextBlock Text="{localView:Translate Destination}" ToolTip="{localView:Translate DriveLogTooltip}" />
</telerik:GridViewDataColumn.Header>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<ComboBox x:Name="destinationComboBox" ItemsSource="{Binding Path=PossibleDestinations}" IsEditable="True"
LostFocus="DestinationComboBox_LostFocus"
SelectedItem="{Binding Path=Entity.Destination,
Mode=TwoWay}"
>
<ComboBox.Text>
<Binding Path="Entity.Destination" Mode="TwoWay"
>
<Binding.ValidationRules>
<model:DestinationValidationRule ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</ComboBox.Text>
</ComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Question 1: In dayDriveLogGridView_CellValidating, I get the expected e.NewValue when changing Kilometers, but not when changing Destination (whenever I input any string, e.NewValue is still null). I'd like to handle all my validations the same way in the codebehind... but it seems like I have to dig out Destination from the EditingElement ???
Question 2: It seems like the DestinationValidationRule gets activated and gives the combobox a red border. But for some reason, this does not bubble out, making the cell invalidated. Can this be done elegantly in XAML? Or in the code-behind.
To me, it seems like that in order to make validation, I need a way to hook the cell up with the combobox (either the rule or the cellvalidation) go most smoothly. Did I miss something?
(I did read http://www.telerik.com/help/wpf/gridview-managing-data-validation.html )
The viewmodel has a property called DriveLog. DriveLog is an observable collections of DriveLogEntryViewModel - each with the property Entry of type DriveLogEntry. DrivLogEntry is a Linq2SQL entity (autogenerated).