/*************************************************************
        * Function: dataGridView1_CellEndEdit(object sender, DataGridViewCellCancelEventArgs e)
        * Date Created: Feb 8, 2017
        * Date Last Modified: Feb 9, 2017
        * Description: dataGridView1_CellEndEdit
        * Return: void
        *************************************************************/
        void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex, column = e.ColumnIndex; string m_Text;

            IUndoRedoCmd[] undos = new IUndoRedoCmd[1];

            Cell tempCell        = ssheet.GetCell(row, column);

            undos[0] = new RestoreText(tempCell.Text, tempCell.Name);

            try
            {
                m_Text = dataGridView1.Rows[row].Cells[column].Value.ToString();
            }
            catch (NullReferenceException)
            {
                m_Text = "";
            }

            tempCell.Text = m_Text;
            //get a temp cmd for undo;
            multiCmds tmpcmd = new multiCmds(undos, "cell text change");

            //push in undo stack
            UnRedo.AddUndos(tmpcmd);

            dataGridView1.Rows[row].Cells[column].Value = tempCell.Value;

            refreshUndoRedoButtons();
        }
Exemple #2
0
        void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int    row = e.RowIndex;
            int    col = e.ColumnIndex;
            string NewText;

            UndoRedoCwd[] undoStack = new UndoRedoCwd[1];

            Cell CorrespondingCell = testSpreadsheet.GetCell(row, col);

            try
            {
                NewText = dataGridView1.Rows[row].Cells[col].Value.ToString();
            }
            catch (NullReferenceException)
            {
                NewText = "";
            }

            // restore the spreadsheet
            undoStack[0] = new RestoreText(CorrespondingCell.Text, CorrespondingCell.Name);
            // reset the text in the cell
            CorrespondingCell.Text = NewText;
            // add undo command with cell text change description
            UndoRedo.addUndo(new UndoRedoCollection(undoStack, "cell Text Change"));
            dataGridView1.Rows[row].Cells[col].Value = CorrespondingCell.Value;
            //update drop down menu
            UpdateMenuText();
        }
Exemple #3
0
        private void dataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            Cell currentCell = this.test.GetCell(e.RowIndex, e.ColumnIndex);

            dataGridView[e.ColumnIndex, e.RowIndex].Value = currentCell.Text;
            Color newColor = Color.FromArgb((int)currentCell.BGColor);

            dataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = newColor;
            ICmd     text    = new RestoreText(currentCell, currentCell.Text);
            ICmd     bgcolor = new RestoreBGColor(currentCell, currentCell.BGColor);
            ICmd     multi   = new MultiCmd();
            MultiCmd temp    = multi as MultiCmd;

            temp.Add(text);
            temp.Add(bgcolor);
            test.AddUndo(multi);
        }
Exemple #4
0
 private void changeColorToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (colorDialog.ShowDialog() == DialogResult.OK)
     {
         Color newColor = colorDialog.Color;            //Save the user selected color
         dataGridView.BackgroundColor = newColor;       //Save the new color in dataGridView.BackgroundColor
         var currentCells = dataGridView.SelectedCells; //Get the highlighted cells
         for (int i = 0; i < currentCells.Count; i++)
         {
             Cell currentCell = test.GetCell(currentCells[i].RowIndex, currentCells[i].ColumnIndex);
             currentCell.BGColor = (uint)newColor.ToArgb(); //Update the background color of each selected cell to the saved color the user selected
             ICmd     text    = new RestoreText(currentCell, currentCell.Text);
             ICmd     bgcolor = new RestoreBGColor(currentCell, currentCell.BGColor);
             ICmd     multi   = new MultiCmd();
             MultiCmd temp    = multi as MultiCmd;
             temp.Add(text);
             temp.Add(bgcolor);
             test.AddUndo(multi);
         }
     }
 }
        // 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();
        }
Exemple #6
0
        // fire when the user stops editing the cell
        private void dataGridView1_CellEndEdit(object sender,
                                               DataGridViewCellEventArgs e)
        {
            // get the row and column of the cell that we need to update
            int cellRow    = e.RowIndex;
            int cellColumn = e.ColumnIndex;

            // get the actual cell
            Cell cellToUpdate = m_spreadsheet.GetCell(cellRow, cellColumn);

            // boolean to check whether the cell's text
            // was actually changed (i.e. the user clicked
            // into the cell then clicked out without
            // changing anything
            bool checkEdit = true;

            // create a RestoreText ICmd for the text change
            RestoreText[] undoText = new RestoreText[1];

            // store the old text of the cell for a potential undo
            string oldText = cellToUpdate.Text;

            // instantiate the RestoreText with the oldText
            undoText[0] = new RestoreText(cellToUpdate, oldText);

            if (cellToUpdate != null)
            {
                // check to see if the user deleted the text of a cell
                try
                {
                    // if the cell's text didn't change but there was text in the cell
                    if (cellToUpdate.Text == dataGridView1.Rows[cellRow].Cells[cellColumn].Value.ToString())
                    {
                        checkEdit = false;
                    }

                    // update the Text property of the cell to notify subscribers
                    cellToUpdate.Text = dataGridView1.Rows[cellRow].Cells[cellColumn].Value.ToString();
                }
                catch (NullReferenceException)
                {
                    // if the cell didn't have text before and after the edit
                    if (cellToUpdate.Text == null)
                    {
                        checkEdit = false;
                    }

                    cellToUpdate.Text = "";
                }

                // update that cell in the spreadsheet to display its Value property
                dataGridView1.Rows[cellRow].Cells[cellColumn].Value = cellToUpdate.Value;

                // only add an undo if the cell was actually edited
                if (checkEdit == true)
                {
                    // add the text change to the undo stack
                    m_spreadsheet.AddUndo(new MultiCmd(undoText, "cell text change"));

                    // update the edit menu options to display correctly
                    UpdateEditMenu();
                }
            }
        }
 public IUndoRedoCmd Execute()
 {
     var inverse = new RestoreText(Current, Current.Text); // Creates the inverse class -> restores to this
     Current.Text = CellText; // restores the cell's text to the contained text
     return inverse;
 }