Exemple #1
0
        /// <summary>
        /// This method functions whenever the user changes something in the contents text box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int col;
            int row;

            //gets the coordinates of the current selected cell
            spreadsheetPanel1.GetSelection(out col, out row);
            //focuses on the content text box
            contentsBox.Focus();
            //automatically brings the cursor to the end of the text in the text box
            contentsBox.SelectionStart = contentsBox.Text.Length;

            //sets the value to the cell of whatever was typed in the contents box
            spreadsheetPanel1.SetValue(col, row, contentsBox.Text);
            //storing the contents of the selected cell
            object contents = formSpreadsheet.GetCellContents(asciiConverter(col, row));

            try
            {
                //if the contents box isnt a formula
                if (!contentsBox.Text.StartsWith("="))
                {
                    //storing the dependent cells of that current selected cell in an list
                    ISet <string> list = formSpreadsheet.SetContentsOfCell(asciiConverter(col, row), contentsBox.Text);
                    //if the content box is empty
                    if (contentsBox.Text == "")
                    {
                        //reevaluating the contents of all the cells that were removed
                        reEvaluateValues((ISet <String>)formSpreadsheet.Remove(asciiConverter(col, row)));
                    }
                    //reevaluate the list again to evaluate all the current cells
                    reEvaluateValues(list);
                }
                //if it is a formula
                if (contentsBox.Text.StartsWith("="))
                {
                    //we make its font blue
                    contentsBox.ForeColor = Color.Blue;
                }
                else
                {
                    //any other contents is displayed in black
                    contentsBox.ForeColor = Color.Black;
                }
            }

            catch (SpreadsheetUtilities.FormulaFormatException)
            {
                //display its contents as "Error"
                spreadsheetPanel1.SetValue(col, row, "Error");
            }
            //displaying the current cell's value in the value box
            valueBox.Text = formSpreadsheet.GetCellValue(asciiConverter(col, row)).ToString();
            //setting the previous column coordinate to the new one
            prevCol = col;
            //setting the previous row coordinate to the new one
            prevRow = row;
        }