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

Capture ADO.NET Entities exceptions with direct binding

3 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
antonio barbero
Top achievements
Rank 1
antonio barbero asked on 25 Aug 2010, 03:26 PM

Hello every body.


I have a RadGridView directly bound to a Ado.Net Entity. Maybe that's not best practice but I have to.

That entity have a property that does not allow null values:


[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String VCOCDC
{
   get { return _VCOCDC;}
   set
   {
     OnVCOCDCChanging(value);
     ReportPropertyChanging("VCOCDC");
     _VCOCDC = StructuralObject.SetValidValue(value, false);
     ReportPropertyChanged("VCOCDC");
     OnVCOCDCChanged();
   }
}

That property is bound to a GridViewComboBoxColumn:


<telerik:GridViewComboBoxColumn Header="{x:Static resc:Resources.Voce}"
    Width="200"
   DisplayMemberPath="VCODSC"
    SelectedValueMemberPath="VCOCDC"
    DataMemberBinding="{Binding VCOCDC}"
    Name="cl_VCOCDC"
    IsGroupable="False"                                              
    IsComboBoxEditable="False"
/>


When inserting a new row on the grid (BeginInsert()), if the user leaves the current row without to choose a value on the combobox , an exception is raised at the row:


 _VCOCDC = StructuralObject.SetValidValue(value, false);

I can't capture the exception, unless i set a global handler, but even so, I would not know what to do, so the application quit.


Questions:


How can I prevent this exception and enforce the user to select a correct value or she can't leave the field? I tried the RowValidating event but that exception is fired before the RowValidating event is raised.


Best Regards

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 30 Aug 2010, 11:50 AM
Hello antonio barbero,

The problem is that value for this property is not valid. This validation is performed between CellValidating and CellValidated events.
Could you please try to handle this case within CellValidating event?
I'm sure that exception won't be raised.

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
0
AndyL
Top achievements
Rank 1
answered on 10 Sep 2011, 08:24 PM

Hi,
Is there any way to handle this exception on entity class level without writing extra validation code   in
CellValidating

 

Thanks,

Andy

0
Nedyalko Nikolov
Telerik team
answered on 15 Sep 2011, 10:27 AM
Hello Andyl,

I'll try to clarify the editing mechanism. CellValidating event is fired just before the actual commit. You could use this event to do UI layer validation (without call to property setter). Then RadGridView calls BindingExpression.UpdateSource() method, which takes care about the commit (calls setter) and does some custom DataAnnotations validation. Then CellValidated event is raised with the result of this Data layer validation.
In other words RadGridView has no control over you BO property setters, just calls then in a right moment.

All the best,
Nedyalko Nikolov
the Telerik team

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

Tags
GridView
Asked by
antonio barbero
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
AndyL
Top achievements
Rank 1
Share this question
or