This is a migrated thread and some comments may be shown as answers.

UpdateSourceTrigger=PropertyChanged ignored in the GridView

1 Answer 681 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 15 Oct 2012, 09:36 AM
I've looked through your forum about this but can only find half working workarounds.

Consider the following GridView:

<telerik:RadGridView ItemsSource="{Binding ItemsView}" AutoGenerateColumns="False"
        IsSynchronizedWithCurrentItem="True"
        ValidatesOnDataErrors="InViewMode" 
        EditTriggers="CellClick"
        CanUserDeleteRows="True"
        CanUserInsertRows="True">
    <telerik:RadGridView.Columns>
        <telerik:GridViewComboBoxColumn Header="Currency" 
            DataMemberBinding="{Binding CurrencyCode,UpdateSourceTrigger=PropertyChanged}" 
            ItemsSource="{Binding Path=DataContext.AllCurrencyCodes,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
            />
        <telerik:GridViewDataColumn Header="Rate"
            DataMemberBinding="{Binding Rate,UpdateSourceTrigger=PropertyChanged,NotifyOnValidationError=True,ValidatesOnDataErrors=True}"
            />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

Here I bind to POCO objects that implement INotifyPropertyChanged. As soon as a change is detected, I light up a Save button.
However, the property does not get changed until the user steps out of the cell, thus preventing the immediate click on the save button!

There is a workaround for simple textboxes;
<telerik:GridViewDataColumn Header="Rate" 
        DataMemberBinding="{Binding Rate,UpdateSourceTrigger=PropertyChanged,NotifyOnValidationError=True,ValidatesOnDataErrors=True}"
    <telerik:GridViewDataColumn.CellEditTemplate
        <DataTemplate
            <TextBox Text="{Binding Rate,UpdateSourceTrigger=PropertyChanged,NotifyOnValidationError=True,ValidatesOnDataErrors=True}"/> 
        </DataTemplate
    </telerik:GridViewDataColumn.CellEditTemplate
</telerik:GridViewDataColumn>

However, this trick fails miserably for Date-fields, since your otherwise great date picker gets supressed. :(

I really want a fix for this, that I consider a bug. Is there any chance of that ever happening?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 15 Oct 2012, 12:20 PM
Hello,

The reason for this behaviour is that the RadGridView overrides and changes the "Binding.UpdateSourceTrigger" property to be "Explicit". It is designed like so because the editing and validation mechanism of RadGridView explicitly updates and validates values when the edit is over. Otherwise validation and commit would happen on every key stroke.

However, as you have found, you could overcome that with a few lines of code using GridViewColumn.CellEditTemplate property and setting binding for the element in Edit mode (i.e. TextBox). Another approach would be to create a custom column serving your needs.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Mattias
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or