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

[Solved] Validation on DataBinding

3 Answers 122 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Morgan McCollough
Top achievements
Rank 1
Morgan McCollough asked on 22 Feb 2010, 07:06 PM
I have been working on trying to get validation to work during the data binding process on RadGridView in Silverlight with no luck. Is this even possible?

Basically, I have a list of data I am importing and binding to the grid. The grid is serving as an intermediary before being posted into the database. I would like to be able to import the data and display it in the grid to the user along with all validation messages so they know what they need to fix before the actual database import happens. Can this work with something like the BindingValidationError event?

I am using the Beta build for Silverlight 4 and Visual Studio 2010. Below is an example of one of my data columns. Maybe I misunderstood what these options are supposed to do. During the bind operation I would like to ensure that the contents of the 'Season' string are actually valid and will import into the database correctly. I added an event handler for 'CellValidating' and set the IsValid property for this particular column to false, but the event only seems to fire when you actually edit something in the UI and NOT during the binding operation. There must be a way around this or something basic I am missing...

<telerikGrid:RadGridView x:Name="BaseDataGrid" RowValidated="BaseDataGrid_RowValidated"  AutoGenerateColumns="False" 
                                         ItemsSource="{Binding BaseData, Mode=TwoWay}" Style="{StaticResource RefGridStyle}" DataLoadMode="Asynchronous" 
                                         MultipleSelect="True" SelectionMode="Extended" RowIndicatorVisibility="Collapsed" ValidationMode="Cell" 
                                         CellValidating="BaseDataGrid_CellValidating" EditTriggers="CellClick, Default">  
<telerikGrid:RadGridView.Columns> 
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Path=Season, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"/>  
</telerikGrid:RadGridView.Columns> 
</telerikGrid:RadGridView> 

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 23 Feb 2010, 03:07 PM
Hi Morgan McCollough,

You can take a look at this blog post which can give you an idea how to meet your goals.
Let me know if this does not help.

Greetings,
Nedyalko Nikolov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Morgan McCollough
Top achievements
Rank 1
answered on 23 Feb 2010, 04:56 PM
Hi,

Thanks so much for your quick response. Maybe I was not quite clear. I have actually seen that blog post, and I understand how all the basic validation stuff works. What I would like to be able to do is mark certain cells as having failed validation during the data bind or data load process.

Let me spell out the scenario a little clearer. The user will click a button to browse to a file they want to import, the code reads from the file and populates the string properties of an object for each row of incoming data. This collection of objects is then bound to the grid and displayed to the user. Before the user actually edits anything, I would like the grid to show all validation errors so that they immediately know what to go and fix before moving the data to the next stage in the process (which will be a database import).

The problem I have is that the validation events like CellValidating aren't thrown until the user actually edits something in the grid directly, and I haven't found any way to mark the cell as invalid when the data is actually loaded.

The approach I am taking at the moment is storing all of the errors discovered while reading the file and then manually changing the background color and adding a tooltip for every cell where validation failed once the data is actually loaded in the grid. When they correct the problem by actually editing in the grid, the color will be changed back to the original and the tooltip removed.

It would be nice to be able to do this by just changing an IsValid flag directly on the cell, but this only seems to be available in the CellValidating event arguments. Am I missing something? Thanks, again!
0
Nedyalko Nikolov
Telerik team
answered on 25 Feb 2010, 03:22 PM
Hello Morgan McCollough,

Unfortunately in Silverlight 3 interface IDataErrorInfo is missing, so this scenario cannot be done out of the box. In Silverlight 4 this interface will be available and RadGridView will support it either for data load and update (edit).
However there is a very nice workaround. Take a look at the attached example I think it will give you some ideas how to meet your goals.

How to use sample application:
1. Click on "Validate" button.
2. Correct the "Age" field by entering an even value, and then click on "Validation" button again.

Let me know how this works on your end.

Regards,
Nedyalko Nikolov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Morgan McCollough
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Morgan McCollough
Top achievements
Rank 1
Share this question
or