c# code for sum and average datagridview column in .net



This is A C# Practice code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using System.Data.SqlClient;


      namespace dataentry
      {
          public partial class UserLogin : Form
          {
              public UserLogin()
              {
                  InitializeComponent();
              }
            
      private void button5_Click(object sender, EventArgs e)
              {
                  int A = 0, B = 0;
                  for (A = 0; A < dataGridView1.Rows.Count; ++A)
                  {
                      B += Convert.ToInt32(dataGridView1.Rows[A].Cells[4].Value);
                  }
                  label10.Text = B.ToString();
              }

              private void button6_Click(object sender, EventArgs e)
              {
                  {
                      int A = 0, B = 0;
                      for (A = 0; A < dataGridView1.Rows.Count; ++A)
                      {
                          B += Convert.ToInt32(dataGridView1.Rows[A].Cells[4].Value);
                      }
                      int NUMofROWS = dataGridView1.Rows.Count;
                      double AVG = B / NUMofROWS;
                      label11.Text = AVG.ToString();
                  }

              }

              private void button8_Click(object sender, EventArgs e)
              {
                  int A = 0, B = 0;
                  for (A = 0; A < dataGridView1.Rows.Count; ++A)
                  {
                      B += Convert.ToInt32(dataGridView1.Rows[A].Cells[5].Value);
                  }
                  label13.Text = B.ToString();
              }

              private void button7_Click(object sender, EventArgs e)
              {

                  int A = 0, B = 0;
                  for (A = 0; A < dataGridView1.Rows.Count; ++A)
                  {
                      B += Convert.ToInt32(dataGridView1.Rows[A].Cells[5].Value);
                  }
                  int NUMofROWS = dataGridView1.Rows.Count;
                  double AVG = B / NUMofROWS;
                  label12.Text = AVG.ToString();
              }

          }
      }

Video For Result:



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment