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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:45:16+00:00 2026-06-04T17:45:16+00:00

I am very confused and have spent a long time trying to debug this

  • 0

I am very confused and have spent a long time trying to debug this event. I have a column and I want to add the first 3 cells in the column and update the 4th cell to be the sum of the first 3.

This works the very first time I populate the first 3 cells. Afterwards, if I try to edit any cell again, the 4th cell won’t change its value. It ONLY works if I edit the 1st cell.

Does anyone know why this is happening? Here is the small part of my code that does this:

int sum = 0;
for (int i = 0; i < 3; i++)
{
  if (dataGridView1.Rows[i].Cells[1].Value == null)
    sum += 0;
  else
    sum += int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) *  int.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
}
dataGridView1.Rows[3].Cells[1].Value = sum;

Those lines of code are within the dataGridView1_CellEndEdit function, so occurs after I change a cell’s value.

  • 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-04T17:45:18+00:00Added an answer on June 4, 2026 at 5:45 pm

    A few things I notice about this that should probably be confirmed/fixed.

    if (dataGridView1.Rows[i].Cells[1].Value == null)
        sum += 0; 
    else
        sum += int.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) * 
            int.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
    

    With this line, what exactly are you doing? You’re checking for a value in the second column of the row in question here, but then you only ever add items from the first column (and multiply each by some number from the first row, second column). This isn’t exactly clear what you’re trying to do. That’s one of the difficulties with dealing with DataGridViews, is that there’s a lot more guesswork than modifying a bound data source. For example, are you sure the column (indexes) actually reference the items you’re interested in? Are you keeping it consistent? Also, I believe the CellEndEdit event only fires when focus is lost from a particular cell after being edited.

    I’m going to give some modified code, but without knowing some additional info I might just be getting this wrong. Based on what you said, you only want the sum of the first 3 values of a column, so that’s what this code does. If this is wrong, please tell me and I’ll correct it (if I can).

    // Note: Using DataGridView[int col, int row] syntax
    int sum = 0;
    
    for (int i = 0; i < 3; i++)
    {
        if (dataGridView1[1,i] != null)
            sum += int.Parse(dataGridView1[1,i].ToString());
    }
    
    dataGridView1[1,3] = sum;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very confused. I have this lambda expression: tvPatientPrecriptionsEntities.Sort((p1, p2) => p1.MedicationStartDate .Value
I'm very confused with this wee little problem I have. I have a non-indexed
Very confused over this. I've just started learning about pointers and have now decided
I am very confused on this topic. I have a webservice on another machine.
hey all, I'm very confused here, i've been trying to figure this one out.
I have used Struts2 in a period time, but I am still very confused
I'm sure this would have been asked before, but I'm very confused! Say I
I have read the docs and everything but I'm very confused. I never needed
Very confused here, trying out the yuicompressor on a simple javascript file. My js
I'm very confused with JavaScript methods defined in objects and the this keyword. In

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.