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

Show validation after insert exception

4 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Björn
Top achievements
Rank 1
Björn asked on 26 Jan 2012, 05:06 PM
I use the GridView in a fashion similar to your example in http://www.telerik.com/help/wpf/gridview-managing-data-add-new-entries.html:
private void radGridView_RowEditEnded( object sender, GridViewRowEditEndedEventArgs e )
{
    if ( e.EditAction == GridViewEditAction.Cancel )
    {
        return;
    }
    if ( e.EditOperationType == GridViewEditOperationType.Insert )
    {
        //Add the new entry to the data base.
        DBUtility.AddEmployee( e.NewData );
    }
}

My "DBUtility.AddEmployee" may return an exception due to a database constraint (e.g. duplicate key). Is there a suggested way to handle this? Any special event?
I would like the result to look approximately the same way as if I was using RowValidating and set the IsValid property to false.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Björn
Top achievements
Rank 1
answered on 30 Jan 2012, 11:22 AM
Anyone?
It doesn't have too look like RowValidating/IsValid=false...
0
Nedyalko Nikolov
Telerik team
answered on 30 Jan 2012, 01:05 PM
Hi,

Generally RadGridView supports various data validation methods like IDataErrorInfo + INotifyPropertyChanged, DataAnnotation attributes and so on. In your case I think that IDataErrorInfo approach is the best for your case, just return any error for a specific property and RadGridView will show it accordingly. Be aware to call also PropertyChanged for this property, since IDataErrorInfo has no notification part.

Kind regards,
Nedyalko Nikolov
the Telerik team

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

0
Björn
Top achievements
Rank 1
answered on 30 Jan 2012, 01:38 PM
Thank you Nedyalko.

Will using IDataErrorInfo also stop the item from being added to the grid as well? Or is it to late to stop the item from being added when the event RowEditEnded has been fired?
0
Nedyalko Nikolov
Telerik team
answered on 30 Jan 2012, 02:44 PM
Hello,

IDataErrorInfo cannot stop adding items to RadGridView. It only provides information about errors and RadGridView will show "red borders" accordingly, but the item will be in RadGridView.Items collection.

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
Björn
Top achievements
Rank 1
Answers by
Björn
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or