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
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.
- DataGridView1.Rows.Add("Joken", 3, 7.5, 22.5)
- DataGridView1.Rows.Add("Batuto", 1, 8, 8)
- DataGridView1.Rows.Add("Intong", 2, 20, 40)
- DataGridView1.Rows.Add("Sansolis", 3, 4, 12)
- 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.
- Dim total As Double
- For i As Integer = 0 To DataGridView1.RowCount - 1
- total += DataGridView1.Rows(i).Cells(3).Value
- 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:
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.