Пример #1
0
        // CELLENDEDIT
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            // What cell did we edit?
            int row    = e.RowIndex;
            int column = e.ColumnIndex;

            //Need add to the undo stack in this class. First declare an array of our command interface
            IUndoRedoCommand[] undos = new IUndoRedoCommand[1];

            // variable for the cell's text
            string text;

            // Get that cell from our spreadsheet
            Cell editedCell = spreadsheet.GetCell(row, column + 1);

            // Get the value from the cell we are editing and apply it to text field
            if (dataGridView1.Rows[row].Cells[column].Value == null)
            {
                text = " ";
            }
            else
            {
                text = dataGridView1.Rows[row].Cells[column].Value.ToString();
            }

            //add the text that will be replaced to the undo stack
            undos[0] = new RestoreText(editedCell, editedCell.Text);

            // set the text of the cell to the newly inputed text
            editedCell.Text = text; // This should also update the value of the cell

            //add the undo array to the undoRedo varaiable of the form along with a descriptive title of what it would be undoing if we called it.
            undoRedo.AddUndo(new UndoRedoCollection(undos, "Cell Text Change"));

            //set the grid cell to the value (evaluated) of the spreadsheet cell
            dataGridView1.Rows[row].Cells[column].Value = editedCell.Value;

            //Update the edit menu
            UpdateEditMenu();
        }