Exemplo n.º 1
0
        /// <summary>
        /// Update the displayed value of all the cells that need to be changed after a cell value is set.
        /// </summary>
        /// <param name="cellsToChange"></param>
        private void UpdateCells(ISet <string> cellsToChange)
        {
            foreach (string cellName in cellsToChange)
            {
                //get the numeric row, col position of the cell
                int col = Convert.ToChar(cellName.Substring(0, 1)) - 65;
                int row = Convert.ToInt16(cellName.Substring(1)) - 1;

                if (visited.Contains(cellName))
                {
                    visited.Clear();
                    break;
                }

                //update the cell state in the spreadsheet
                ss1.UpdateCell(cellName);

                visited.Add(cellName);

                //update the GUI
                if (ss1.GetCellValue(cellName).GetType() != typeof(FormulaError))
                {
                    spreadsheetPanel1.SetValue(col, row, ss1.GetCellValue(cellName).ToString());
                }
                else
                {
                    spreadsheetPanel1.SetValue(col, row, "Formula Error!");
                }

                //update all dependent cells
                HashSet <string> dependents = new HashSet <string>(ss1.getDependentCells(cellName));
                UpdateCells(dependents);
            }
        }