We help IT Professionals succeed at work.
Get Started

Validation of cells in Datagrid

bigmacisdn asked
Last Modified: 2007-12-19
I am working on a simple purchase order system in VB.NET 2003
I have a dataset that has a purchase order header (purchtable) and the purchase order lines. (purchlines), joined on purchase Order number.

My form has 2 datagrids.  
The top datagrid is connected to purchtable, and shows a list of purchase orders.  
The bottom datagrid is connected to purchlines and shows the related lines of the purchase order.

When you click on a purchase order in the top grid, the lines of the purchase order automatically show in the bottom grid.

One of the fields in the purchase order line is an item number (ie Inventory Part number) .  (My system has another table of valid items that can be purchased.)

So, when the user keys in an item number, I want to validate the item number against the valid items table.  If it is not valid, I want to issue an error message (via msgbox,  or .SetColumnError or something)

The solution MUST cover the following situations;

The validation must occur when the user moves off the cell containing the item number.  (either via mouse or keyboard) .

If the field is in error, the user must not be able to move to another row in the grid or move the focus to any other part of the form (especially moving to another order by clicking on the order grid). Also the user must not be able to close the form with the item in error.

The cursor should be placed back on the item field in error.

The solution must cover the situation where the users moves to the end of the orderlines grid (creating a new record), and enters an invalid item.

Obviously I can do the actual item # validation code.  My question is more about the events (cellchanged, column changing) etc etc.  I just can't work it out.


Neil Macpherson

Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE