How to Add Footer Row In DataGridView With Total In A Column


This tutorial about “How to Add Footer Row In DataGridView With Total In A Column” will help you answer the problem regarding adding a total row in datagridview especially when you are doing a Sales Inventory Reports or summary. To start with this application, follow the steps provided below.

How to Add Footer Row In DataGridView With Total In A Column

Step 1: Create a Visual Basic Project

  • Open Visual Basic 2008/2010, and Create a new project
  • Save it as “FooterRow”

Step 2: Design the Form

  • Add 1 DataGridview and a Button
  • Then Follow the Design show below.

add footer row

add footer row

Step 3: Adding of Codes

  • we are going to Populate the datagridview with Data to do this, Double click the form and on the Form1_Load add the following code.
  1. DataGridView1.Rows.Add("Joken", 3, 7.5, 22.5)
  2. DataGridView1.Rows.Add("Batuto", 1, 8, 8)
  3. DataGridView1.Rows.Add("Intong", 2, 20, 40)
  4. DataGridView1.Rows.Add("Sansolis", 3, 4, 12)
  5. DataGridView1.Rows.Add("Peter", 5, 4.25, 21.25)
  • Next, to compute the total we to use a loop that will read and Get the total Sales. To do this, Double click the Button and add the Following Code.
  1. Dim total As Double
  2. For i As Integer = 0 To DataGridView1.RowCount - 1
  3. total += DataGridView1.Rows(i).Cells(3).Value
  4. Next
  5. DataGridView1.Rows.Add(Nothing, Nothing, "Total", total)


Step 4: Run the Project.

  • Press F5
  • or, Click the Play Button

The running Program looks like as shown below:

add footer row1
add footer row1

Note* You can do this using a data from the database.

If you have any questions or suggestion please feel free to drop a message at our contact page.


Download the full source code here:

Facebook Comments


Please enter your comment!
Please enter your name here