Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Totals Row in a DataGridView

I am developing a winform application application. I wanted to show sum of columns in last row of each column. This row must always be visible.

At moment I am thinking about adding another datagridview just beneath my datagridview with records, and would show the sum in that bottom datagridview.

If there is a better way to achieve this task?

like image 409
fawad Avatar asked Sep 14 '25 19:09

fawad


2 Answers

No, need of adding another datagridview

Solution 1: Please refer to this solution

Solution 2: If the above link is not exactly what you want then,

You can try to manually add last, summary, row in which you can display information that you need. For example, you can try to do the following:

  1. Read data from database and fill System.Data.DataTable
  2. Add one column to the newly created DataTable – that column might be set to true for the last, summary, row
  3. Programmatically add one extra row that contains suitable summary data
  4. Do the data binding to DataGridView control
  5. Using appropriate event, bold or otherwise graphically distinct summary row (row that have extra column value set to true)
like image 85
Marshal Avatar answered Sep 17 '25 03:09

Marshal


You can do it in the same way as you suggest, like placing a datagridview for displaying the sum. you can also handle the Horizontal Scroll with this, if there are more columns.

Another method is there in this link

Another way you can Add Rows to your datasource itself to display the sum.

like image 39
Binil Avatar answered Sep 17 '25 01:09

Binil