Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

adding total row to datagrid in window forms .net

Posted on 2004-08-08
3
Medium Priority
?
254 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

971 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