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

CellTemplate with IDataErrorInfo

5 Answers 171 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rostislav
Top achievements
Rank 1
Rostislav asked on 04 May 2017, 06:57 AM

Hi,

I am trying to create a GridView with both Cell and CellEdit templates for one of the columns. The problem that I am experiencing is two fold:

1. If I bind the column AND the CellTemplate to the same property, I noticed that the IDadaErrorInfo indexer gets called twice per "Name" cell. This is a problem as the validation logic is not particularly straight forward and starts to create a performance issue once there are few dozen rows:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name, ValidatesOnDataErrors=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
    <telerik:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Name, ValidatesOnDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

2. Removing the DataMemberBinding from the column and keeping it in the CellTemplate works fine when it comes to displaying the data, but does not seem to work with the IDataErrorInfo. I can see the indexer get called, however I do not see the validation error reflect in the UI. Which effectively means that the validation can only be shown in CellEditTemplates:

<telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name, ValidatesOnDataErrors=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
    <telerik:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Name, ValidatesOnDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

 

What is the correct way of setting up Cell and CellEdit template binding to display IDataErrorInfo errors in both edit and non-edit mode at all times, while not having the IDataErrorInfo indexer getting hit twice as much as it should?

 

Thanks in advance,

Ross

5 Answers, 1 is accepted

Sort by
0
Rostislav
Top achievements
Rank 1
answered on 04 May 2017, 07:03 AM
We are using Telerik.Windows.Controls version 2013.1.0403.40 and .Net 4.0
0
Martin
Telerik team
answered on 08 May 2017, 12:22 PM
Hi Rostislav,

I tried a similar solution with the second solution presented from you on my side and unfortunately, I was not able to reproduce the problem. Everything works as expected including that the validation error reflects in the UI. Attached you can find the project I used for the test. Please give it a try and let me know in case I am missing something.

Regards,
Martin Vatev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Rostislav
Top achievements
Rank 1
answered on 15 May 2017, 07:10 AM

Hi Martin,

Thanks for your reply and sample solution! I should have been more clear in my original question. The issue that I'm having in 2nd point is that when I leave the CellEditTemplate - either by pressing the ESC key or by setting the ValidatesOnDataErrors="InViewMode" for the grid, the CellTemplate does not show the validation error.

For example - the your sample solution:

1. Run the application

2. Select "Liverpool" in row 1, cell 1 and replace it with "1"

3. Press TAB

Expected and Actual: Row 1, cell 1 is highlighted in red due to name being too short

4. Press ESC key

Expected: Row 1, cell 1 red highlight remains

Actual: Row 1, cell 1 red highlight disappears, as if there is no issue

The way to work around this issue and display the errors at all times can be done by changing the MainWindow.xaml file:

1. Add "ValidationOnDataErrors="InViewMode" to the RadGridView

2. Add "DataMemberBinding="{Binding Name, ValidatesOnDataErrors=True, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"" to the first GridViewDataColumn

These changes will result in red hihglight being visible at all times after focus out, but will result in the IDataErrorInfo Indexer in Club.cs being hit many more times that it should :(

I hope I was a little clearer with my explanation this time!

0
Martin
Telerik team
answered on 16 May 2017, 05:15 PM
Hi Rostislav,

Now I already reproduced the issue. Most likely this is some old bug that has already been fixed. I tried with our latest version and everything works as expected. The only thing that I can suggest is to get it.

I hope that this helps.

Regards,
Martin Vatev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Rostislav
Top achievements
Rank 1
answered on 16 May 2017, 11:34 PM

Hi Martin,

Thanks for the confirmation. Looks like this is another good reason for us to upgrade to the latest version!

Thanks again,

Ross

Tags
GridView
Asked by
Rostislav
Top achievements
Rank 1
Answers by
Rostislav
Top achievements
Rank 1
Martin
Telerik team
Share this question
or