//Populate the 2d array with the cells. public spreadSheet(int rowNum, int colNum) { grid = new cellArray[rowNum, colNum]; int i = 0; int j = 0; for (i = 0; i < rowNum; i++) { for (j = 0; j < colNum; j++) { cellArray newCell = cellArray.makeCell(i, j); grid[i, j] = newCell; newCell.PropertyChanged += eventHandle; } } }
public void eventHandle(object sender, PropertyChangedEventArgs e) { Dictionary <string, double> newDict = new Dictionary <string, double>(); if ("Text" == e.PropertyName) { cellArray c = (sender as cellArray); if (c.Text[0] != '=') { c.changeCellValue(c.Text); } else { string newText = c.Text; ExpTree newTree = new ExpTree(newText.Substring(1)); c.references.Clear(); //findCol = Convert.ToInt32(newText[1] - 65); //findRow = Convert.ToInt32(newText.Substring(2)) - 1; newTree.popDict(); foreach (KeyValuePair <string, double> x in newTree.backUp) { int findCol = Convert.ToInt32(x.Key[0] - 65); int findRow = Convert.ToInt32(x.Key.Substring(1)) - 1; string cellName = x.Key; if (!c.references.Contains(cellName)) { c.references.Add(x.Key); } char col = (char)(c.columnIndex + 65); //change to c related text. string rowString = (c.rowIndex + 1).ToString(); string currentCell = string.Format("{0}{1}", col, rowString); Cell tempCell = findCell(findRow, findCol); if (!tempCell.referencedBy.Contains(currentCell)) { tempCell.referencedBy.Add(currentCell); } //string cellName = Convert.ToString(c.columnIndex + 65) + Convert.ToChar(c.rowIndex); //tempCell.referencedBy.Add(cellName); if ((grid[findRow, findCol].Value.ToString()) != "") { newDict.Add(x.Key, Convert.ToDouble(grid[findRow, findCol].Value)); } else { continue; } } newTree.backUp.Clear(); foreach (KeyValuePair <string, double> x in newDict) { newTree.backUp.Add(x.Key, x.Value); } newTree.popM(); if (c.changeCellValue(newTree.Eval().ToString()) != "0") { c.changeCellValue(newTree.Eval().ToString()); } else { c.changeCellValue(""); } //this.Text = grid[findRow, findCol].Value;//** } newDict.Clear(); //c.setVal(this.grid); funcellPropertyChanged(sender as Cell, "CellValue"); } //c.setVal(this.grid); }