Windows Form DataGridView - RowValidating Event Not Firing

Posted on 2009-02-09
Last Modified: 2013-11-26
I'm Developing a Windows Forms application with a datagridview bound to a datasource. In the process of validating some cell values the RowValidating Event does not fire when navagation moves off the row. Works fine moving to Next Row. However, if i change a cell value, Tab back to the left to another cell on the same row, then use the mouse to click on a Previous row above the changed row..... the RowValidating Event does not occur.
   A B  C D
1 x  x  x  x
2 x  x  x  x
3 x  x  x  x

If I change the value in C2, then backtab (or mouse click) back to B2, Then mouse click on any cell in row 1, the RowValidation Event does not fire and thus the changed value in C2 does not get evaluated. I am manually handling the Datasource Update which is dependant on the validations. Please advise ...
Question by:mpharis
    LVL 48

    Assisted Solution

    That's a validation for the row, not for the cells. Use CellValidating event instead

    Author Comment

    Therein lies the initial problem. I am using CellValidating but if one cell is dependant on another I cannot navagate away from the invalid cell to change the parent cell controlling the validation logic. Example:
    I have both a "Company" column and a "Division" Column. Both columns may have a valid entry for each independent cell but there are only certain valid "Divisions" for a given "Company". I was attempting to use Cell validation for the individual values and then apply RowValidating to ensure the validity of the group "Company and Division".  Otherwise,  a valid company and division would pass the first line of validations and allow the Update of an Invalid Company/Division combination.
    I'm open to other approach to this kind of issue?
    LVL 48

    Expert Comment

    Can you show what you're doing ?

    Accepted Solution

    Let me diverge from the intial description to the REAL Issue.
      The idea revolves around a product ID column of an order detail line in a datagridview. I'd like the user to have the option of typing in the product ID or clicking a "Button" in the next column which would display another Gridview (like a Pop-Up) and allow the customer to select the product ID. The concept is to have a button column which the user could click if he/she input the wrong ID and select the Correct One.
       The problem, if the user inputs an invlaid Product ID, CellValidating Fires and prevents the user from navagating away and clicking the Button which would display the valid options to select from. I'm not sure how to handle the scenario so I tried using the RowValidating event for the Product ID to allow for the Button Selection. Sorry for the confusing description. Does what i'm attempting make sense?
    Note-I'm using a second datagridview instead of a combobox column in my initial DGV because i what to provide more information for the user to have availble like description, price, Onhand qty, etc..

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now