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

Manually trigger validation on RadGridView

0 Answers 331 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Davidm
Top achievements
Rank 1
Davidm asked on 16 Dec 2011, 03:59 PM
I want to validate my RadGridView manually by pressing a button, but I cant' get this to work. If I set the validator to ValidatesOnTargetUpdated="True" the validation works, but I want to trigger this validaton manually. Here is the XAML code of my DataColumn:

<telerik:GridViewDataColumn Header="Error" >
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <telerik:GridViewCell>
                <telerik:GridViewCell.DataContext>
                    <Binding NotifyOnValidationError="True" >
                        <Binding.ValidationRules>
                            <validators:MyValidator  />
                        </Binding.ValidationRules>
                    </Binding>
                </telerik:GridViewCell.DataContext>
                <telerik:GridViewCell.Style>
                    <Style TargetType="{x:Type telerik:GridViewCell}" >
                        <Style.Triggers>
                            <Trigger Property="Validation.HasError" Value="true">
                                <Setter Property="ToolTip"
                                    Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                                    Path=(Validation.Errors)[0].ErrorContent}"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </telerik:GridViewCell.Style>
                <telerik:GridViewCell.Content>
                    <TextBlock Text="!!!" />
                </telerik:GridViewCell.Content>
            </telerik:GridViewCell>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

I' ve managed to get the validator in codebehind and check every item in the datagrid, but I also have to set the bindings as invalid for the cells to display the error. I found the command System.Windows.Controls.Validation.MarkInvalid() for this, but for this command to work I need to get the binding expression of every cell. How can I get these binding expressions?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Davidm
Top achievements
Rank 1
Share this question
or