Click here to Skip to main content
15,890,947 members
Home / Discussions / C#
   

C#

 
GeneralRe: VS_FIXEDFILEINFO implementation in C# Pin
OriginalGriff29-Oct-15 1:18
mveOriginalGriff29-Oct-15 1:18 
GeneralRe: VS_FIXEDFILEINFO implementation in C# Pin
Member 1206160029-Oct-15 1:22
Member 1206160029-Oct-15 1:22 
GeneralRe: VS_FIXEDFILEINFO implementation in C# Pin
Dave Kreskowiak29-Oct-15 4:03
mveDave Kreskowiak29-Oct-15 4:03 
GeneralRe: VS_FIXEDFILEINFO implementation in C# Pin
Member 1206160029-Oct-15 5:16
Member 1206160029-Oct-15 5:16 
Questionc# Pin
Member 1152168528-Oct-15 20:42
Member 1152168528-Oct-15 20:42 
AnswerRe: c# Pin
OriginalGriff28-Oct-15 22:44
mveOriginalGriff28-Oct-15 22:44 
AnswerRe: c# Pin
John Torjo28-Oct-15 23:15
professionalJohn Torjo28-Oct-15 23:15 
Questionpivot - Variab;le y axis Pin
Member 1206164728-Oct-15 9:15
Member 1206164728-Oct-15 9:15 
Hello All exoperts,

below code which I saw in code project wi;l;l do a pivot of a data set where x,y,z axis are fixed, I just want to have 4 column to be used as y axis , can I do that ?

what I understood frpom the code,

y axis value is stored in a ;list

List<string> columnYValues = new List<string>();

and it was return at

foreach (string columnYValue in columnYValues)
{
//Creates a new Row
DataRow drReturn = returnTable.NewRow();
drReturn[0] = columnYValue;

can I return other y axis cpo;lumn in same way with in the same ;loop\.

///
/// Gets a Inverted DataTable
///

/// <param name="table" />Provided DataTable
/// <param name="columnX" />X Axis Column
/// <param name="columnY" />Y Axis Column
/// <param name="columnZ" />Z Axis Column (values)
/// <param name="columnsToIgnore" />Whether to ignore some column, it must be
/// provided here
public static DataTable GetInversedDataTable(DataTable table, string columnX,
string columnY, string columnZ, string nullValue, bool sumValues)
{
//Create a DataTable to Return
DataTable returnTable = new DataTable();

if (columnX == "")
columnX = table.Columns[0].ColumnName;

//Add a Column at the beginning of the table
returnTable.Columns.Add(columnY);


//Read all DISTINCT values from columnX Column in the provided DataTale
List<string> columnXValues = new List<string>();

foreach (DataRow dr in table.Rows)
{

string columnXTemp = dr[columnX].ToString();
if (!columnXValues.Contains(columnXTemp))
{
//Read each row value, if it's different from others provided, add to
//the list of values and creates a new Column with its value.
columnXValues.Add(columnXTemp);
returnTable.Columns.Add(columnXTemp);
}
}

//Verify if Y and Z Axis columns re provided
if (columnY != "" && columnZ != "")
{
//Read DISTINCT Values for Y Axis Column
List<string> columnYValues = new List<string>();

foreach (DataRow dr in table.Rows)
{
if (!columnYValues.Contains(dr[columnY].ToString()))
columnYValues.Add(dr[columnY].ToString());
}

//Loop all Column Y Distinct Value
foreach (string columnYValue in columnYValues)
{
//Creates a new Row
DataRow drReturn = returnTable.NewRow();
drReturn[0] = columnYValue;
//foreach column Y value, The rows are selected distincted
DataRow[] rows = table.Select(columnY + "='" + columnYValue + "'");

//Read each row to fill the DataTable
foreach (DataRow dr in rows)
{
string rowColumnTitle = dr[columnX].ToString();

//Read each column to fill the DataTable
foreach (DataColumn dc in returnTable.Columns)
{
if (dc.ColumnName == rowColumnTitle)
{
//If Sum of Values is True it try to perform a Sum
//If sum is not possible due to value types, the value
// displayed is the last one read
if (sumValues)
{
try
{
drReturn[rowColumnTitle] =
Convert.ToDecimal(drReturn[rowColumnTitle]) +
Convert.ToDecimal(dr[columnZ]);
}
catch
{
drReturn[rowColumnTitle] = dr[columnZ];
}
}
else
{
drReturn[rowColumnTitle] = dr[columnZ];
}
}
}
}
returnTable.Rows.Add(drReturn);
}
}
else
{
throw new Exception("The columns to perform inversion are not provided");
}

//if a nullValue is provided, fill the datable with it
if (nullValue != "")
{
foreach (DataRow dr in returnTable.Rows)
{
foreach (DataColumn dc in returnTable.Columns)
{
if (dr[dc.ColumnName].ToString() == "")
dr[dc.ColumnName] = nullValue;
}
}
}

return returnTable;
}
AnswerRe: pivot - Variab;le y axis Pin
OriginalGriff28-Oct-15 22:45
mveOriginalGriff28-Oct-15 22:45 
AnswerRe: pivot - Variab;le y axis Pin
Richard MacCutchan28-Oct-15 22:48
mveRichard MacCutchan28-Oct-15 22:48 
Questionhow to read a serial data and then observe it in a box with c#? Pin
ssssdaaads28-Oct-15 3:25
ssssdaaads28-Oct-15 3:25 
AnswerRe: how to read a serial data and then observe it in a box with c#? Pin
Richard MacCutchan28-Oct-15 4:05
mveRichard MacCutchan28-Oct-15 4:05 
GeneralRe: how to read a serial data and then observe it in a box with c#? Pin
ssssdaaads28-Oct-15 4:33
ssssdaaads28-Oct-15 4:33 
QuestionUnit test of Asynchronous Block not happening Pin
Ashfaque Hussain28-Oct-15 0:57
Ashfaque Hussain28-Oct-15 0:57 
AnswerRe: Unit test of Asynchronous Block not happening Pin
Dave Kreskowiak28-Oct-15 4:02
mveDave Kreskowiak28-Oct-15 4:02 
AnswerRe: Unit test of Asynchronous Block not happening Pin
Nicholas Marty28-Oct-15 5:02
professionalNicholas Marty28-Oct-15 5:02 
GeneralRe: Unit test of Asynchronous Block not happening Pin
Ashfaque Hussain28-Oct-15 21:52
Ashfaque Hussain28-Oct-15 21:52 
QuestionFonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Prem9527-Oct-15 23:14
Prem9527-Oct-15 23:14 
SuggestionRe: Fonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Richard MacCutchan27-Oct-15 23:35
mveRichard MacCutchan27-Oct-15 23:35 
AnswerRe: Fonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Gerry Schmitz28-Oct-15 6:35
mveGerry Schmitz28-Oct-15 6:35 
QuestionNot allowed to change the 'ConnectionString' property. The connection's current state is connecting. Why I am getting this error? Pin
Member 1200209527-Oct-15 20:09
Member 1200209527-Oct-15 20:09 
AnswerRe: Not allowed to change the 'ConnectionString' property. The connection's current state is connecting. Why I am getting this error? Pin
John Torjo27-Oct-15 21:55
professionalJohn Torjo27-Oct-15 21:55 
QuestionPlugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
jappi8827-Oct-15 7:04
jappi8827-Oct-15 7:04 
AnswerRe: Plugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
Eddy Vluggen27-Oct-15 7:48
professionalEddy Vluggen27-Oct-15 7:48 
GeneralRe: Plugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
John Torjo27-Oct-15 10:59
professionalJohn Torjo27-Oct-15 10:59 

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.