Datagridview cell Verification

Source: Internet
Author: User

To solve this problem, we thought it was easy to use canceledit. Who knows it's not that easy.

It is said that the function execution sequence is:

Reprinted from: http://dangfang800.blog.163.com/blog/static/32243525200781695130664/

The following lists the order of events such as validation, enter/leave, and begin/end (when editmode is editonenter ):

When moving from one cell to another(In the same row):

1) cell leave (original cell)

2) cell validating/ED (original cell)

3) cell endedit (original cell)

4) cell enter (new cell)

5) cell beginedit (new cell)

When moving from one row to another:

1) cell leave (original cell) and row leave (original row)

2) cell validating/ED (original cell)

3) cell endedit (original cell)

4) Row validating/ED (original row)

5) Row enter (new row)

6) cell enter (new cell)

7) cell beginedit (new cell)

 

Then, if the verification fails in cell leave, validating, and validated, canceledit will fail! The values in these functions are the values before modification.

So the solution is:

Use cell endedit and record the values before modification in cell leave or validate. If the verification fails, it will be restored in endedit. In this way, another member of the class is added ~

 

I wonder if there are any other better solutions?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.