Click here to Skip to main content
15,905,913 members
Home / Discussions / C#
   

C#

 
GeneralRe: System.Timers problem Pin
TylerBrinks15-Mar-05 8:20
TylerBrinks15-Mar-05 8:20 
GeneralPassing Safearray parameter to WebBrowser COM component Pin
simcho9915-Mar-05 3:45
simcho9915-Mar-05 3:45 
QuestionHow to show a child form when parent form is busy? Pin
oohungoo15-Mar-05 3:25
oohungoo15-Mar-05 3:25 
AnswerRe: How to show a child form when parent form is busy? Pin
tdciDoug15-Mar-05 4:22
tdciDoug15-Mar-05 4:22 
GeneralRe: How to show a child form when parent form is busy? Pin
oohungoo15-Mar-05 19:18
oohungoo15-Mar-05 19:18 
AnswerRe: How to show a child form when parent form is busy? Pin
James Poulose15-Mar-05 8:24
James Poulose15-Mar-05 8:24 
GeneralPivot table in .net Pin
Prabhakar.A15-Mar-05 3:20
Prabhakar.A15-Mar-05 3:20 
GeneralRe: Pivot table in .net Pin
Ravindra Sadaphule15-Mar-05 5:33
Ravindra Sadaphule15-Mar-05 5:33 
Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc.

Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below.

The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table.


//Create Destination Table
DataTable dest = new DataTable("Pivot" );

// from each source table row (1st column)
// create a destination column
foreach( DataRow r in source.Rows )
dest.Columns.Add( r[0].ToString() );

// assign each row the Product name Now that we have the appropriate columns defined

in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name.
//Create columns in destination table for each row in source table.
for( int i = 0; i < source.Columns.Count - 1; i++ )
dest.Rows.Add( dest.NewRow() );


The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop.
//Transpose rows and columns
for( int r = 0; r < dest.Rows.Count; r++ )
for( int c = 0; c < source.Columns.Count; c++ )
dest.Rows[r][c] = source.Rows[c][r];


Ravindra Sadaphule
MCSD.NET
GeneralRe: Pivot table in .net Pin
Prabhakar.A15-Mar-05 19:50
Prabhakar.A15-Mar-05 19:50 
GeneralReflex between objects! Help! Pin
oohungoo15-Mar-05 3:15
oohungoo15-Mar-05 3:15 
GeneralRe: Reflex between objects! Help! Pin
mav.northwind15-Mar-05 4:32
mav.northwind15-Mar-05 4:32 
GeneralTake this as challenging task for smart device application Pin
sivaji raju15-Mar-05 2:31
sivaji raju15-Mar-05 2:31 
GeneralComboBox Pin
Bahadir Cambel15-Mar-05 2:29
Bahadir Cambel15-Mar-05 2:29 
GeneralRe: ComboBox Pin
Ravindra Sadaphule15-Mar-05 7:02
Ravindra Sadaphule15-Mar-05 7:02 
GeneralRe: ComboBox Pin
Bahadir Cambel15-Mar-05 7:31
Bahadir Cambel15-Mar-05 7:31 
GeneralRe: ComboBox Pin
Ravindra Sadaphule15-Mar-05 7:37
Ravindra Sadaphule15-Mar-05 7:37 
GeneralRe: ComboBox Pin
Bahadir Cambel15-Mar-05 7:43
Bahadir Cambel15-Mar-05 7:43 
Generaldisplay custom column names in datagrid Pin
itssuk15-Mar-05 2:11
itssuk15-Mar-05 2:11 
GeneralRe: display custom column names in datagrid Pin
Ravindra Sadaphule15-Mar-05 7:12
Ravindra Sadaphule15-Mar-05 7:12 
GeneralWinforms IDE problem Pin
Fragging15-Mar-05 1:37
Fragging15-Mar-05 1:37 
GeneralRe: Winforms IDE problem Pin
Robert Rohde15-Mar-05 6:36
Robert Rohde15-Mar-05 6:36 
GeneralRe: Winforms IDE problem Pin
Ravindra Sadaphule15-Mar-05 7:15
Ravindra Sadaphule15-Mar-05 7:15 
GeneralRe: Winforms IDE problem Pin
Fragging15-Mar-05 7:47
Fragging15-Mar-05 7:47 
QuestionHow to identify user, who runs a certain process? Pin
3Dizard15-Mar-05 1:28
3Dizard15-Mar-05 1:28 
AnswerRe: How to identify user, who runs a certain process? Pin
Scott Serl15-Mar-05 10:34
Scott Serl15-Mar-05 10:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.