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 7177579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:44:40+00:00 2026-05-28T16:44:40+00:00

hi i have a datagridview whose first column (index = 0) is a checkbox

  • 0

hi i have a datagridview whose first column (index = 0) is a checkbox column. i want to update a label when a cell is checked and unchecked. my function seems to work fine, but it doesn’t update the label until the next cell in that column is changed.

when the form loads all rows are checked, so say 4 of 4. i uncheck one row and the label doesn’t update. i uncheck another row and then it says 3, so you see it’s working a step behind.

i’ve tried a few different DataGridViewCellEvents like CellValueChanged, CellStateChanged, CellEndEdit, but they all act the say way. i do still need to have a DataGridViewCellEventArgs e so i can check the column.

any suggestions?

private void fileGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                int numberOfFiles = 0;
                for (int i = 0; i < fileGrid.Rows.Count; i++)
                {
                    Console.WriteLine(fileGrid[0, i].Value.ToString());
                    if (fileGrid[0, i].Value.ToString() == "True")
                    {
                        numberOfFiles++;
                    }
                }
                numberOfFilesLabel.Text = numberOfFiles.ToString();
            }
        }

i can’t answer my own question yet, but this is what i used to accomplish:

private void fileGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                int numberOfFiles = 0;
                for (int i = 0; i < fileGrid.Rows.Count; i++)
                {
                    Console.WriteLine(fileGrid[0, i].Value.ToString());
                    if (fileGrid[0, i].Value.ToString() == "True")
                    {
                        numberOfFiles++;
                    }
                }

                if (fileGrid.IsCurrentCellDirty)
                    fileGrid.CommitEdit(DataGridViewDataErrorContexts.Commit);

                if (fileGrid.CurrentCell.Value.ToString().Equals("True"))
                {

                    numberOfFiles++;
                }
                if (fileGrid.CurrentCell.Value.ToString().Equals("False"))
                {

                    numberOfFiles--;
                }
                numberOfFilesLabel.Text = numberOfFiles.ToString();
            }
        }
  • 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-05-28T16:44:40+00:00Added an answer on May 28, 2026 at 4:44 pm

    this happens because the edited value is not committed directly after changing the checkbox. its committed, when you leave the editor.
    you have to commit the value immediately to get the behaviour you want.
    one way i found, but did not try is this one:

    private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
            if (e.ColumnIndex == 0)
            {
                if (dataGridView2.IsCurrentCellDirty)
                    dataGridView2.CommitEdit(DataGridViewDataErrorContexts.Commit);
    
                if (dataGridView2.CurrentCell.Value.ToString().Equals("True"))
                {
                    MessageBox.Show("Now do the job while checked value changed to True.");
                    //
                    // Do the job here.
                    //
                }
            }
    }
    

    EDIT:

    demo solution.

    public partial class Form1 : Form
    {
        class MyClass
        {
            public bool Check { get; set; }
            public string Name { get; set; }
        }
    
        public Form1()
        {
            InitializeComponent();
    
            List<MyClass> lst = new List<MyClass>();
            lst.AddRange(new[] { new MyClass { Check = false, Name = "item 1" }, new MyClass { Check = false, Name = "item 2" } });
            dataGridView1.DataSource = lst;
        }
    
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                if (dataGridView1.IsCurrentCellDirty)
                    dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    
                if (dataGridView1.CurrentCell.Value.ToString().Equals("True"))
                {
                    MessageBox.Show("Now do the job while checked value changed to True.");
                    //
                    // Do the job here.
                    //
                }
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question should be self explanatory. I have a datagridview which has a column whose
I have datagridview with checkbox column, and the checkbox within the column can be
I have datagridview with checkboxcolumn. How can I detect when checkbox state in cell
I have a form that contains dataGridView, whose coloumn are set to dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;
I have a DataGridView that I want to query using Linq (C# WinForm). I
I have a datagridview which im binding DataTable to. What I want do is
I have a dataGridView whose dataSource is a dataTable. My problem is that I
I am using vb.net 2010. I have a datagridview whose data source is a
I have a DataGridView whose datasource is a BindingList. MyObj has a few nullable
I have one DataGridView and want to make the Header text Bold. I have

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.