Click here to Skip to main content
14,332,414 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

I have a datagridview with multiples rows from database.

The content of my datagrid can be printed, on every page can be printed only 45 record + 1 record for the SUM of the last tow columns.

How can i calculate the SUM for every 45 records? I don't know haw many record are in the database, can be 25 or 500.

OK,

I have the following table.

No. Column1 Column2 Column3 Column4
1 some data some data 20 30
2 some data some data 20 30
3 some data some data 20 30
................................................
45 some data some data 20 30
46 some data some data 20 30
................................................
89 some data some data 20 30
90 some data some data 20 30
................................................

To calculate the SUM of column3 for all rows i use:
for (int i = 0; i < datagridview.Rows.Count; ++i)
            {
                suminchise += Convert.ToDouble(datagridview.Rows[i].Cells[3].Value);
            }

But, in my printing are displayed only 45 record on every page, and i need to calculate the sum of the column3 only for the first 45 row, and for page to for record 46 to 90, next 91 to 135, etc...
Posted
Updated 21-Oct-12 19:45pm
v2
Comments
   
Can you elaborate a little ? I am not clear about the requirement ?
Aciobanita Costel 21-Oct-12 12:30pm
   
I populate my datagrid from a datatable. The content of my datagrid is printed in report, on a page i can display only 45 record from my datagridview, and in the bottom of the printed page a want to display the SUM of a column only for the record in that page. On the next page are displayed the next 45 rows, and the end the sum for the record that are displayed on the second page, ETC. The number of the record isn't know, Can be 2 or 500,
   
SUM of a coulmn ??? I can't make this out.
Can you give one simple example what SUM you will show in the bottom row ?
Aciobanita Costel 22-Oct-12 1:44am
   
OK,

I have the following table.

No. Column1 Column2 Column3 Column4
1 some data some data 20 30
2 some data some data 20 30
3 some data some data 20 30
................................................
45 some data some data 20 30
46 some data some data 20 30
................................................
89 some data some data 20 30
90 some data some data 20 30
................................................

To calculate the SUM of column3 for all rows i use:
for (int i = 0; i < datagridview.Rows.Count; ++i)
{
suminchise += Convert.ToDouble(datagridview.Rows[i].Cells[3].Value);
}
But, in my printing are displayed only 45 record on every page, and i need to calculate the sum of the column3 only for the first 45 row, and for page to for record 46 to 90, next 91 to 135, etc...
   
Have you done paging to your DataGridView ?
If yes, what is the pagesize ?
Aciobanita Costel 22-Oct-12 2:09am
   
The paging is done by Stampa Reports, and in the design of the page the table accept only 45 record (set by me).

I don't know how to do paging the datagridview, i will search to see it. tanks
   
Do paging in DataGridView and then calculate SUM for column3 pagewise and do your task...
a1mimo 21-Oct-12 14:54pm
   
what kind of reports do you use? if you use windows reporting service it has a feature to add this row for you, please make your question more clear
Aciobanita Costel 22-Oct-12 1:44am
   
i use Stampa reports.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

int a[]=new int[7];
for (int i = 0; i < datagridview.Rows.Count; ++i)
            {
                  

                suminchise += Convert.ToDouble(datagridview.Rows[i].Cells[3].Value);
                if(i%45==0)
                {
                  a[j]=suminchise;
                  j++;
                  suminchise=0;
                }
                
            }


u can use a[0],a[1],.... as sum of every 45 record...and if sappose u have 100 records then u wil got
a[0]=sum of 1st 45 record
a[1]=sum of 2nd 45 record
and
suminchise=sum of rest 10 records;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100