Get Column Total Value in DataGridView - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial will show you how to count records values in DataGridView

This tutorial will continue Display Access table records in DataGridView

In this case we will add up the prices in Price column

add record values in datagridview

Get Total of Prices Button Click

Private Sub CountButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CountButton.Click
        Dim total As String = 0
        For i As Integer = 0 To DataGridView1.RowCount - 1
            total += DataGridView1.Rows(i).Cells(2).Value 
            'Change the number 2 to your column index number (The first column has a 0 index column)
            'In this example the column index of Price is 2
        Next
        TextBox1.Text = total
End Sub

datagridview column values


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.