Solved

adding total row to datagrid in window forms .net

Posted on 2004-08-08
3
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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
Name Space error VS2015 1 48
Help with viewing image in ReportViewer 14 32
Datatable / Dates ? 4 33
Datagriview cell not show all data 4 11
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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