Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:31:05+00:00 2026-06-09T23:31:05+00:00

I have a DataGridView which one of its columns is a DataGridViewCheckBoxColumn. When I

  • 0

I have a DataGridView which one of its columns is a DataGridViewCheckBoxColumn. When I check a cell of this column, I validate if two other cells in the same row (but in different columns) are 0. If both are 0, then I want to cancel the new value entered for the checkbox column (consume the event and ignore the change on it). That is: if you check it and other two columns are both 0 (in the same row), then I want to keep uncheck the checkbox cell.

I do this by handling the CellValidating event. Inside it I check if these two cells (in the same row)are both 0 and if so and user has checked the checkbox cell (also in the same row) then I do e.Cancel = true, in order to keep unchecked the checkbox cell and ignore the check done by user.

But it is not working, I have seen that e.RowIndex in CellValidating event does not correspond to the row index on which I have just clicked but e.ColumnIndex is correct…

In summary, what I want is that when user checks the checkbox column of a row, if the other two columns values are both set to 0 for the same row, I want to keep the checkbox column unchanged (it remains with its old value, for example if it was unchecked and user checks it, it will remain unchecked). Otherwise if these two columns are not both set to 0, checkbox column will take it into account, for example, if it was unchecked and user checks it, it will change to checked.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:31:07+00:00Added an answer on June 9, 2026 at 11:31 pm

    I would use a different event than CellValidating. I would use CellBeginEdit

    dataGridView1.CellBeginEdit += CellBeginEdit;
    
    private void CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
    {
        DataGridView dgv = (DataGridView)sender;      
        if (dgv[0, e.RowIndex].Value == "2") # or whatever conditions you want to check
        {
            e.Cancel = true;
        }
        else
        {
            e.Cancel = false;
        }
    }
    

    I believe CellValidating gets called on the whatever cell you were previously on and that is why the row index doesn’t make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagridview in which one column contains a custom class, which I
I have a DataGridView in which one column has data that the user needs
I have few columns in my DataGridView, one of them is an unbound column
i have datagridview which has one combobox column. i populate combobox column. when i
I have a DataGridView which is filling from Table in SQL Server Database. One
I have a datagridview column 'total',in which I am doing sum of rates of
I am working on an application in which I have two database fields. One
I have a datagridview which is bound to some data. One of the fields
I have a datagridview which I'm using for data entry. I've done this before
I have a datagridview bound to a datatable. One of the columns in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.