Solved

use SUM and date difference in the datagrids with a dataset

Posted on 2003-12-06
3
246 Views
Last Modified: 2010-04-16
using windows application.

first form details:  two datagrids--first for main table, second for sub table (they are related in dataset)
how do I sum the column containing rows of numbers into a single row of total amount in the "sub table" datagrid ?

second form:  same as above.  
how do I set up the date difference--"sub table" datagrid with three columns (col 1 - previous date, col 2 - current date, col 3 - date difference by DAYS)

the data comes from a xml file and is stored in the dataset.  I don't know if i need to do something with xml schema...

hope these details help...thanks
0
Comment
Question by:rizel
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
Comment Utility
First problem: handle the DataGrid.CurrentCellChanged for the main grid, thus finding the moment when the records in the sub table changed. You will then be able to get the current row in the main DataGrid. Use the DataRow.GetChildRows to get the rows that are shown in the related child table and calculate manually the sums. Add a new row to the child table including the summed values. Be careful: maybe you will have to clear the previous sum row.

Links:
- DataGtrid.CurrentCellChanged: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclasscurrentcellchangedtopic.asp
- DataRow.GetChildRows: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatarowclassgetchildrowstopic.asp

Second problem: create a table with two columns for the two dates you want to calculate the difference from. Then create a third column and use SQL statements to set the DataColumn.Expression property to calculate the value of the third column. You will have to play a little bit with the expression because directly subtracting the columns will probably return the difference in millilseconds.

Links:
- DataColumn.Expression: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

11 Experts available now in Live!

Get 1:1 Help Now