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. Image for the cookie policy date
close icon

Define Validation rules for SfDataGrid

Hi forum,

I would like to set validation rules for the entire data grid or a column.
Is there an example for this?

regards
Thomas

6 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team June 18, 2019 07:16 AM UTC

Hi Thomas, 
  
Thanks for using Syncfusion product. 
  
You can able to validate the data in a column by using DataAnnotation attributes by setting SfDataGrid.GridValidationMode or GridColumn.GridValidationMode property to InEdit or InView. 
  
Please refer the below code example, 
  
<syncfusion:SfDataGrid x:Name="grid" 
                       AutoGenerateColumns="False" 
                       GridValidationMode="InView" 
                       ItemsSource="{Binding UserDetails}"> 
  
  
[Range(10000, 30000, ErrorMessage = "The “Salary” field can range from 10000 through 30000.")] 
public int Salary 
{ 
    get { return salary; } 
    set { salary = value; OnPropertyChanged("Salary"); } 
} 
  
  
You can also validate the cells and rows using CurrentCellValidating and RowValidating events in SfDataGrid. You can refer the below UG and KB links for your further details, 
  
  
  
Regards, 
Jagadeesan 



TB Thomas Beimel June 18, 2019 02:59 PM UTC

Hi Jagadeesan,
thanks for your anwser.
But it is not possible to define validation rules like a textbox?



regards
Thomas


TB Thomas Beimel June 18, 2019 03:03 PM UTC

Here the screen shot missing in my last post.

Attachment: ValidationRule_7f505acc.zip


SP Shobika Palani Syncfusion Team June 19, 2019 01:11 PM UTC

Hi Thomas,  
 
Thanks for your update. 
We have analyzed your query , We regret to inform you that currently we don’t have a support for “Applying validation rules in SfDataGrid”. We have already logged this requirement as feature request in our database. We don’t have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest.  We will implement this feature in any of our upcoming release. We will let you know when this feature is implemented. We appreciate your patience until then  
 
Please login to view the feedback further,  
 
Also as mentioned in our previous update, You can use custom validation using CurrentCellValidating and RowValidating events or you can use built in validation using IDataErrorInfo/InNotifyDataErrorInfo instead of ValidationRule.  
 
Please refer the below UG link for IDataErrorInfo.  

Regards, 
 
Shobika. 



TB Thomas Beimel June 25, 2019 09:46 AM UTC

Hi,

I got it to work with the INotifyDataErrorInfo.
Thanks for your help.

regards
Thomas


FP Farjana Parveen Ayubb Syncfusion Team June 26, 2019 06:39 AM UTC

Hi Thomas, 
Thanks for the update. 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon