For more information, see:
Summary row in the DataGrid Control: http://www.microsoft.com/china/MSDN/library/data/dataAccess/Summary+Rows+in+DataGrid+Controls.rtf.mspx? Mfr = true
Example of resumttable file:
/Files/lovenets2008/FIG
Functions used:
Public static DataTable MakePivotFromTable_Demo (DataTable source, string columeTop, string columeLeft, string columeSum)
{
DataTable dest = new DataTable ("Pivoted" + source. TableName );
// The remaining dest columns are from each source table row (1st column)
// For (int I = 1; I <source. Columns. Count-1; I ++)
//{
// Dest. Columns. Add (source. Columns [I]. ColumnName );
//}
// Source. LoadDataRow (ll, bbbb );
DataTable dtCols = new DataTable ();
DtCols. Columns. Add (columeTop );
DtCols. Constraints. Add ("key", dtCols. Columns [0], true );
Foreach (DataRow r in source. Rows)
{
DtCols. loadDataRow (r [columeTop]. toString (). split (",". toCharArray (), true); // assign each row the Product name (r [0])
}
Dest. Columns. Add (columeTop); // "summary ");
// Dest. Columns. Add (columesSum );
Foreach (DataRow r in dtCols. Rows)
{
Dest. Columns. Add (r [columeTop]. ToString (); // assign each row the Product name (r [0])
}
// Now add one row to the dest table for each column in the source, limit t
// The first which is the Product, in our case
Dest. Constraints. Add ("key", dest. Columns [0], true );
For (int I = 0; I <source. Rows. Count; I ++)
{
Dest. LoadDataRow (source. Rows [I] [columeLeft]. ToString (). Split (",". ToCharArray (), true );
// DataRow dr = dest. NewRow ();
// Dr [0] = source. Rows [I] [columesLeft];
// Try
//{
// Dest. Rows. Add (dr );
//}
// Catch (Exception ){}
}
// Now move the source columns to their position in the dest row/cell matrix
// Starting down the destination rows, and keep ss the columns
For (int r = 0; r <dest. Rows. Count; r ++)
{
For (int c = 1; c <dest. Columns. Count; c ++)
{
Float amounts = 0;
DataRow [] drs = source. Select (source. Columns [columeTop]. ColumnName + "= '" + dest. Columns [c]. ColumnName
+ "'AND" + source. Columns [columeLeft]. ColumnName + "='" + dest. Rows [r] [0]. ToString () + "'");
Foreach (DataRow dr in drs)
{
Amounts + = float. Parse (dr [columeSum]. ToString ());
}
If (drs. Length> 0) dest. Rows [r] [c] = amounts;
}
}
// Dest. Select ();
// DataTable dt = dest. Constraints. Add (;
// Dest. Select ("Select *");
Dest. AcceptChanges ();
Return dest;
}
The progress will be posted here one after another.