Row by row validation

  • Thread starter Thread starter Doc Dunning
  • Start date Start date
D

Doc Dunning

Hi all,

This seems such a simple problem to me but I can't find the answer after
*much* searching.

I have an application using bound controls to browse / update a database
table of club member details. It uses a data grid view to scroll up and
down the list of names, and if I select a row, then some bound text boxes
show the details for the person I've selected. I can edit the text boxes,
and when I click a different row in the grid, any changes I've made are
reflected back into the database. Wonderfully easy to get this far!

But now I want to validate the entries in the text boxes. For example - the
person's surname must not be blank. Seems fair enough to me. I've managed
to find the "rowchanging" event and added the validation in there. I've
been able to add an error provider as well, which uses the "setcolumnerror"
values. If I go back to that record again, t shows a red blob against the
field in error, but ...

.... whatever I do, I can't find how to stop the invalid values being put
back into the dataset :-(. I want to trap the error, point it out to the
user, and have them correct it *before* the row is updated, all before we
navigate away to the next record. This is such common interface design that
it just has to be easy to do, and yet I can't see how.

Any pointers to the solution from out there?

Thanks in advance.
 
Thanks, Ken ... I'd started to go down that track and it did seem to be the
right way to go. But then I realised that fully bound input boxes are not
the easiest way to do validation anyway, so I'm using the datagrid as a
bound control, and then via the CurrentItemChanged event of the
bindingsource, I can copy data from the dataset current record to my
separate text and combo boxes. Then I have a separate "Save" button which
invokes the validation and if all's OK, a beginedit/endedit routine to put
the textboxes back into the dataset. A bit more code, but much more
flexible (imho).

Martin
 
Back
Top