We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to better manage datavalidation in SfDataGrid using AddNewRow

Thread ID:





128811 Feb 10,2017 09:15 AM UTC Feb 22,2017 03:42 AM UTC WPF 4
Tags: SfDataGrid
Asked On February 10, 2017 09:15 AM UTC


please find here attached a project I have modified in order to test and check data validation on SFDatagrid.

I've modified class OrderInfo implementing the interface INotifyDataErrorInfo.
Implementing the interface I've added a check to be sure the property CustomerID is not left black (only as a test).

If I run the example, when I try to add a new row, clicking on the top of the grid, I obtain this behaviour:

1) as soon as I click on the Order ID cell (on the top) a red icon appear correctly on the left. If I move the mouse cursor over it I obtain the generic message "Row containaing error".
2) if I click on "Customer ID" cell and leave the cell empty, I have no warning about the fact the cell is empty.
3) if I press Return, the new record is correctly added to the grid even if there are validation errors.

So, here are, my questions about it:

1) Is there the possibility to configure the tooltip that appears over the red icon on the left? I'd like to let appear a box when all the current  record validation errors are listed, not a generic error like the actual one.

2) Is there the possibility, as soon as I click on the New Row, to let appear a red icon (and related tooltip) on ALL the cells that are not validated (in this case only on the empty Customer ID cell) ?

3) (the most important question) Is there the possibility NOT to add the new record in the datagrid if it is not completly validated? The Return key should add the new record to the datagrid ONLY if all the record is correctly validated.

Thank you for the answer ....

Attachment: AddNewRowDemo_a8fb0812.zip

Replied On February 10, 2017 09:57 AM UTC

To better explain what I ask in my 3th question I clarify that I don't want to abort the add new record action, as I could do calling method 


in the CurrentCellValidated event.
Doing so, in fact, would abort all the changes in the current new record.
I'd like, if possible, the Return Key is aborted (and so no new record is added to the datagrid) while the record is not validated. 
The only way, for the user, to commit a AddNewRecord should be to enter data that is completly validated or to abort all the insertion pressing the Esc Key.

Hoping to have better clarified what I'm searching for ...

Jai Ganesh S [Syncfusion]
Replied On February 11, 2017 12:19 PM UTC

Hi Silvio, 
We have analyzed your queries and please find the responses for your queries as below, 
Query 1: Is there the possibility to configure the tooltip that appears over the red icon on the left? 
You can achieve this requirement for show the all column’s error message in RowHeader by customizing the style of GridRowHeaderCell and using AddNewRowInitiating event, 
this.datagrid.AddNewRowInitiating += Datagrid_AddNewRowInitiating; 
private void Datagrid_AddNewRowInitiating(object sender, Syncfusion.UI.Xaml.Grid.AddNewRowInitiatingEventArgs e) 
    if ((e.NewObject as OrderInfo).CustomerID == null) 
        (this.datagrid.DataContext as ViewModel).ErrorMessages="You must put a not null CustomerID !"; 
<Path x:Name="PART_RowHeaderIndicator" 
                                    <ToolTip x:Name="PART_ToolTip" 
                                         Tag="{Binding ErrorMessages,Source={StaticResource viewmodel}}" 
                                         Template="{StaticResource ValidationToolTipTemplate}" /> 
Query 2: Is there the possibility, as soon as I click on the New Row, to let appear a red icon  
You can achieve this requirement by setting the GridValidationMode as InEdit in SfDataGrid, 
                    EditTrigger="OnTap" GridValidationMode="InEdit" 
                    ItemsSource="{Binding OrderList}" 
Query 3:  Is there the possibility NOT to add the new record in the datagrid if it is not completly validated? 
You can achieve this requirement by wiring the RowValidating event like below, 
this.datagrid.RowValidating += Datagrid_RowValidating; 
private void Datagrid_RowValidating(object sender, Syncfusion.UI.Xaml.Grid.RowValidatingEventArgs e) 
    if ((e.RowData as OrderInfo).CustomerID == null) 
        e.IsValid = false; 
Jai Ganesh S 

Replied On February 21, 2017 09:25 AM UTC

Thank you Ganesh!

It was all very usefull to me !

Jai Ganesh S [Syncfusion]
Replied On February 22, 2017 03:42 AM UTC

Hi Silvio,  
Thank you for the update. 
Please let us know if you need further assistance on this. 
Jai Ganesh S 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon