Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends,i am getting an error in my c# project and the error is my form is automatically closed on form load i want to sum datagridview cell value on load code is below please check it and tell me how can i do this.

What I have tried:

for (int i = 0; i < dataGridView2.Rows.Count; ++i)
            {

                //    sum1 += Convert.ToInt32(dataGridView2.Rows[i].Cells[1].Value);
                //}
                //textBox14.Text = "";
                String example = dataGridView2.Rows[i].Cells[1].Value.ToString();
                Int32 sum1 = example.Split(new char[] { ',' })   // get the "list" of strings
                                   .Select(n => Int32.Parse(n)) // get the "list" of integers
                                   .Sum();
                textBox14.Text = sum1.ToString();
            }
Posted
Updated 4-Mar-17 14:03pm
Comments
[no name] 4-Mar-17 20:10pm    
And you think we can "check it" how? We don't have your forms or your data so what is it that you think we can check for you? Catch the exception that is being thrown, then fix it.
Member 9983063 5-Mar-17 5:41am    
No sir when i use this query so it's happen i just want to know there is any problem in my code
[no name] 5-Mar-17 7:46am    
Well obviously there is a problem with your code and I have already told you what you need to do to find out what it is to fix it.
Member 9983063 5-Mar-17 7:49am    
well now i am using this code for sum
Double sum1 = 0;
int rowIdx1 = dataGridView2.Rows.Count;
for (int i = 0; i < dataGridView2.Rows.Count; ++i)
{
sum1 = Double.Parse(dataGridView2.Rows[i].Cells[1].Value.ToString());
}
textBox14.Text = sum1.ToString();
but it's show nothing
[no name] 5-Mar-17 7:53am    
And I already told you what you need to do to find and fix that too. The error that you are making is that you think we can see your screen, we can't. You are the one sitting in from of your screen with your code so you are the one that needs to figure it out. Learning how to debug your code is a very useful skill that you need to develop.

1 solution

Check for each [FormName].Close() in your code and set a breakpoint on them. If they are being used when they should not be, the debugger will stop your code and show you exactly where.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900