Datagridview Cell Validating Problem

Posted on 2007-08-03
Last Modified: 2008-02-01
I have a cell Validating sub defined for a datagridview where if a cell did not meet some requirements, I set the errortext and prevent the user from moving by having the code e.cancel = true. The reason I have a cell validating defined is because if there is an error there is another grid which I don't user to click on until the error is fixed. The e.cancel = true works fine as soon as I click tab or leave the cell. The e.cancel = true doesn't work when I am still in the cell. what I can do to prevent this. Thanks.
Question by:sandya_116
    LVL 18

    Accepted Solution

    i think u want validation on the textchange of cell.

    What sort of validation u want ?

    Suppose if u want ony numeric or text ten it is possibel. If u want a range then it will be complicated because the event will be fired befor the user completes enrty.
    LVL 34

    Expert Comment

    As the docs say, the CellValidating event [EMPHASIS added] "OCCURS WHEN A CELL LOSES INPUT FOCUS, enabling content validation."  What is cancelled by e.Cancel = True is the (attempted) move out of the cell.  So that it does not work "when I am still in the cell" is by design.  There is no attempted move out of the cell that can be cancelled.

    If you want to validate while the user is still in the cell - that is, still entering/editing its contents - then you will need to use some other event or approach: perhaps, as ajaysharmaapjs suggests, working at the level of the keypress to the editing version of the cell.

    That gets complicated.  I just wonder why you want to work with a different validating model than that which is native to the DataGridView.


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    OleDbDataAdapter.Update 3 32
    Need help with a query 8 44
    Query datatable in LINQ 6 29
    Finding if Numbers are ranges 8 26
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now