Visual C# | DataGridView events exercise | The CellValidating event of a DataGridView

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Software ==> Visual C#  (79 exercises)
Version ==> Any version of C#
Topic ==> DataGridView events  (3 exercises)
Level ==> Average difficulty
Subject ==> C# training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a data source for the Mortgage database in the folder shown above, if you haven't already done so.

Create a form called frmApplicant to contain a DataGridView listing mortgage applicants from the Person table (you may be able to use a version of this form that you've already created):

Visual C Sharp 2010 exercise - DataGridView events (image 1)

Our initial DataGridView

Add code to the CellValidating event of the DataGridView so that when a user enters an invalid amount the application displays an error message, and the user can not leave the cell without correcting the error:

Visual C Sharp 2010 exercise - DataGridView events (image 2)

You can only enter numerical amounts

Add code to display the ErrorText property of the current row if the mortgage type id is not an integer between 1 and 5:

Visual C Sharp 2010 exercise - DataGridView events (image 3)

Don't forget to reset the ErrorText property when a cell is successfully validated

When everything is working OK, close down this form.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post