How To Get The Sum Of DataGridView Column Values In C#
How To Get The Sum Of DataGridView Column Values In C#
Hello friend’s this is Rashid Hussain come with another video tutorial. In this tutorial I’ll show you how to get the sum of datagridview column values in c# winform application
Create new windows Form application in visual studio. follow the steps
drag DataGridView label and button from toolbox.
create database and insert some values
Click on datagridview and add data source
Add the Code below in form.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace SumOfGVColumn { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'database1DataSet.Salary' table. You can move, or remove it, as needed. this.salaryTableAdapter.Fill(this.database1DataSet.Salary); } private void button1_Click(object sender, EventArgs e) { label2.Text = "0"; for (int i = 0; i < dataGridView1.Rows.Count; i++) { label2.Text = Convert.ToString(double.Parse(label2.Text)+double.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString())); } } } }
Video tutorial
Thank you for reading this article. Please don’t forget to subscribe our official YouTube Channel RashiCode