Solved

adding total row to datagrid in window forms .net

Posted on 2004-08-08
3
244 Views
Last Modified: 2012-06-27
How to add the row below datagrid last row which display the total of the column above as in excel
so it behave like excel sheet.
0
Comment
Question by:gary_1nz
3 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11749821
web forms: http://www.dotnetspider.com/Technology/KB/ShowSample.aspx?SampleId=133 http://www.devasp.net/net/search/res/r19286.html

the easiest way is probably to just use aggregate columns (DataColumn.Expression) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp also see http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcreatingexpressioncolumns.asp and http://msdn.microsoft.com/library/en-us/dndive/html/data05312002.asp

an alternative would be to create the new row with code similar to ...

dim dt as DataTable = DataSet.Tables("Whatever")
dim dr as DataRow
dim Totals as DataRow = dt.NewRow()
dim i as integer
for i = 0 to Totals.Columns.Count - 1
      Totals[i] = 0
end for
foreach dr in dt
      for i = 0 to dr.Columns.Count - 1
            Totals[i] += dr[i];
      end for
end for
dt.Rows.Add(Totals)

this code assumes all fields are numeric, for real life you would probably want to check the datatype of the column.

Cheers,

Greg
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now