.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Calculate the Sum of Values from a DataGrid Cell

Posted By:Hefin Dsouza       Posted Date: August 24, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  

This Sample Demonstrates how to Calculate Sum of Values From a


You can use this code in many scenarios.
Like Calculating Sales From a Particular salesman etc.
In This code we will calculate marks of an individual Student.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tot As Integer = 0
For i As Integer = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(i).Cells(1).Value = txtName.Text Then
tot += DataGridView1.Rows(i).Cells(2).Value
End If
If tot = 0 Then
MessageBox.Show("No Records Found")
End If
txtTotal.Text = tot
End Sub
In the Sample Code I have used a Dataset you can use the same code if you are working with a database.
Note * : Do Not Forget to change the index of the columns you want to calculate.

Download The Full Application With Source Code
Regards Hefin Dsouza
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend