private CCellMatrix BuildMatrixFromGrid(DataGridView pDataGrid) { CCellMatrix theMatrix = new CCellMatrix(); CCellVector theCellVector; int i_row = 0; int i_col = 0; foreach (DataGridViewRow row in pDataGrid.Rows) { theCellVector = new CCellVector(); //theMatrix.AddVector(i_row, theCellVector); i_col = 0; bool last_empty_line = true; foreach (DataGridViewCell cell in row.Cells) { string colName = _theMatrix._cellHeaderVector._cellHeaders[i_col]._name; // check if the last row is completely empty in order to insert the vector if (!(cell.Value is null)) { last_empty_line = false; } double cell_value = Convert.ToDouble(cell.Value); //CCell cellToInsert = new CCell(0, cell_value); CCell cellToInsert = new CCell(cell_value.ToString(), i_row); var x = _theMatrix._cellHeaderVector._cellHeaders[i_col]; cellToInsert._cellHeader = _theMatrix._cellHeaderVector._cellHeaders[i_col]; theCellVector.Add(colName, cellToInsert); i_col++; } if (!last_empty_line) { theMatrix.AddVector(i_row, theCellVector); } i_row++; } return(theMatrix); }
public CCellMatrix BuildMatrixFromGrid() { // back the headerVector CCellHeaderVector tCellHeaderVector = _theMatrix._cellHeaderVector; // back the new matrix CCellMatrix theMatrix = new CCellMatrix(); // back the headerVector theMatrix._cellHeaderVector = tCellHeaderVector; CCellVector theCellVector; int i_row = 0; int i_col = 0; foreach (DataGridViewRow row in _theDataGrid.Rows) { theCellVector = new CCellVector(); i_col = 0; bool last_empty_line = true; foreach (DataGridViewCell gridCell in row.Cells) { string colName = _theMatrix.ColumnsHeader[i_col]._name; // check if the last row is completely empty in order to insert the vector // see also comment after the foreach loop if (!(gridCell.Value is null)) { last_empty_line = false; } CCell cellToInsert; if (gridCell.Tag is null) { string cell_value = (string)gridCell.Value; cellToInsert = new CCell(cell_value, i_row); cellToInsert._cellHeader = _theMatrix.ColumnsHeader[i_col]; } else { cellToInsert = (CCell)gridCell.Tag; } theCellVector.Add(colName, cellToInsert); i_col++; } // in the row is not empty it is added if (!last_empty_line) { theMatrix.AddVector(i_row, theCellVector); } i_row++; } return(theMatrix); }