Solved

adding total row to datagrid in window forms .net

Posted on 2004-08-08
3
247 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export data table to excel in vb.net 10 36
write xml in vb.net 2 32
VB.Net - Not Sure if Multi-threading is What I Need 4 29
Help with error in Query 2 31
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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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