Solved

use SUM and date difference in the datagrids with a dataset

Posted on 2003-12-06
3
247 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
ID: 9895036
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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