Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to: Validate data in PropertyGridControl

$
0
0

The DXPropertyGrid supports several ways to check if the value entered by a user is correct.

First, this functionality can be implemented at the View level by handling the ValidateCell event. This event is raised when a user has modified a cell value and is trying to save changes (either by pressing the Enter key or switching to another property grid cell).
Here is a code snippet demonstrating how to handle this event.


[C#]
voidOnPropertyGridControlValidateCell(objectsender,DevExpress.Xpf.PropertyGrid.ValidateCellEventArgse){if(e.NewValue==null||string.IsNullOrEmpty(e.NewValue.ToString()))e.ValidationException=newSystem.Exception("A cell cannot be empty");}

 

Another way is to implement validation at the data source level using Data Annotation Attributes (assigning attributes using the DevExpress FluentAPI is also supported) or by implementing the IDataErrorInfo interface.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>