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

Show validation error for a Telerik RadGridView row

3 Answers 807 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arihant
Top achievements
Rank 1
Arihant asked on 15 Mar 2012, 06:22 AM
I am using telerik radgridview to bind to a collection of my model objects. Also, have added a validation rule class that triggers the validation.


Now i want to show a validation error around the radgridview row in case the error occurs. An custom error template is defined in my resource file.  Below is the xaml for the same.


    <telerik:RadGridView Grid.Column="0" Grid.Row="2"                                  ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                 ItemsSource="{Binding Path=CollectionOfObjects}" SelectedItem="{Binding Path=SelectedObject, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                                 GdEvent:DoubleClickGridViewCommandBehaviour.OnDoubleClick="{Binding Path=GridRowDoubleClickCommand}" 
                                 RowIndicatorVisibility="Collapsed" ColumnWidth="*" EditTriggers="None" IsFilteringAllowed="False" 
                                 AutoGenerateColumns="False" AllowDrop="False" 
                                 CanUserFreezeColumns="False" CanUserReorderColumns="False" 
                                 CanUserDeleteRows="False" CanUserInsertRows="False" ShowGroupPanel="False" 
                                 SelectionMode="Single" SelectionUnit="FullRow">
    <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Width="Auto" Header="Header1" DataMemberBinding="{Binding Header1}" TextAlignment="Left"/>
                    <telerik:GridViewDataColumn Width="Auto" Header="Header2" DataMemberBinding="{Binding Header2}" TextAlignment="Left"/>
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.BindingGroup>
      <BindingGroup NotifyOnValidationError="True">
       <BindingGroup.ValidationRules>
         <util2:ModelValidationRule ValidationStep="ConvertedProposedValue" ValidatesOnTargetUpdated="True" />
       </BindingGroup.ValidationRules>
      </BindingGroup>


But when i run the app, an the validation error fails. it is not showing any error against that row.


Please help
     </telerik:RadGridView.BindingGroup>
    <telerik:RadGridView.Resources>
     <Style TargetType="{x:Type telerik:GridViewRow}">
       <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
       <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
     </Style>
    </telerik:RadGridView.Resources>

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 19 Mar 2012, 02:40 PM
Hi,

Generally you've set a validation rule on RadGridView, but GridViewRow cannot display any error related to RadGridView. If you want to display any row related error inside GridViewRow you should validate data objects and RadGridView will show all validation errors. In order to validate data (business) objects you could use IDataErrorInfo + INotifyPropertyChanged interfaces. I'm attaching a sample application that demonstrates this approach.

Regards,
Nedyalko Nikolov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Arthur
Top achievements
Rank 1
answered on 17 May 2012, 06:12 PM
Hi,

Thanks for the demo.

I was just wondering if you could suggest the best way to provide column based validation in the RadGridView?

We have a cell on each row which is using a drop down box and want to ensure that the value of the drop down box is only used once.

Of course in this instance we would be going across multiple data objects in the bound collection so the validation you demostrated wouldn't work here

Many thanks

Arthur
0
Nedyalko Nikolov
Telerik team
answered on 19 May 2012, 09:27 AM
Hi,

In order to show an error in RadGridView you should return any error message, how you will perform the validation check is not important. Indeed there are some cases when this validation takes a little bit more time, then I would recommend using Telerik.Windows.Data.INotifyDataErrorInfo interface (this interface is similar to the one in Silverlight) instead of IDataErrorInfo.

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Arihant
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Arthur
Top achievements
Rank 1
Share this question
or