Saturday, March 24, 2012

Validation for Duplicate entries in a Datagrid control.

Does anyone know how to check for duplicate entries on a datagrid control before adding a new row?

Any sample codes is greatly appreciated.This sort of checks are better performed on a datasource of the Grid rather than grid itself. Every table should have a primary key to allow the row identification. This way even if there are rows having duplicate data you will be able to tell them apart. If you want to enforce the uniqueness not on a primary key value, then you can have your data in a DataTable, create a DataView on that table and set the RowFilter property of the dataview using the fields/values you want to check for uniqueness. After applying the RowFilter, use the Count property of it to make a decision on what to do - if Count is 0 - add a new row, etc

Bug
Any chance you have a link to some code for this. More of a step by step breakdown for those of us that read your post as if it were another language?

No comments:

Post a Comment