Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am not able to figure out a way to validate user input in a DataGrid control when it is bound to a DataTable. The issues I see are:

  1. I can't add custom validation rules to the data source i.e. DataTable because the only constraints that can be added to it are UniqueConstraint and ForeignKeyConstraint.
  2. Overriding the CellEditEnding event in the grid, and then setting the property e.cancel = true - where argument e is of type DataGridCellEditEndingEventArgs - on invalid input detection doesn't help one bit because the invalid value is anyway assigned to the underlying DataTable.

The input validation I am after are related to business rules, like a decimal value can't be negative, and another value has to be in the range say 10-25. Surely, there must be some way to enforce these rules.

Thanks.

share|improve this question
did you check DataRow.SetColumnError? msdn.microsoft.com/en-us/library/… – blindmeis Jun 5 at 9:23

1 Answer

up vote 1 down vote accepted

you can validate a datatable in ColumnChanging Event and use SetColumnError

share|improve this answer
Yes. It worked. Thanks!!! – Dinesh Bajaj Jun 5 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.