Database Programming Techniques > Validating Cell Data |
If the grid's AllowUpdate property is True, your users will be able to modify the underlying data interactively through the grid's user interface. To prevent users from updating the database with invalid entries, you can write data validation code that works on a per-cell or per-row basis. To validate individual cells, use the BeforeColUpdate event. To validate entire rows, use the BeforeUpdate event.
For certain kinds of data, such as dates and phone numbers, you can use the EditMask property to specify an input template that filters out illegal characters as they are typed. Even if you use True DBGrid's built-in input masking features, you may still want to write data validation code. For example, the user may enter a phone number that is syntactically legal, but contains a bogus area code. Since the grid knows nothing about area codes, you would have to write a handler for either BeforeColUpdate or BeforeUpdate in order to prevent the invalid number from being written to the underlying data source.