• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

use SUM and date difference in the datagrids with a dataset

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
1 Solution
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.

- 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.

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

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now