Example #1
0
        private void dataGridView1_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
        {
            string originalCellText = "";
            if (null == currSheet) { return; }
            //Var (undoRedoPush) holds a collection of undo and redo commands

            DataGridViewCell UIcell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
            SpreadSheet.UndoRedo.UndoRedoCollection undoRedoPush = new SpreadSheet.UndoRedo.UndoRedoCollection();
            SpreadsheetEngine.Cell dataCell = currSheet.GetCell(e.RowIndex, e.ColumnIndex);

            originalCellText = dataCell.Text;
            //save original text


            //Set text for the UI cell and trigger the event to update the cell value
            if (null == UIcell.Value) { dataCell.Text = string.Empty; }

            else { dataCell.Text = UIcell.Value.ToString(); }

            //Set the value for the UI cell to the cell value
            UIcell.Value = dataCell.Value;

            undoRedoPush.addCollection(new SpreadSheet.UndoRedo.UndoRedoCollection("text", dataCell, originalCellText));

            reloadEntireSheet();
            Undo_Redo.UndoPush(undoRedoPush);
            ReloadRedo();
            reloadUndo();
        }
Example #2
0
        private void changeColorToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ColorDialog colorD = new ColorDialog();
            colorD.AllowFullOpen = true;
            colorD.AnyColor = true;
            colorD.ShowDialog();

            SpreadSheet.UndoRedo.UndoRedoCollection pushUndoRedo = new SpreadSheet.UndoRedo.UndoRedoCollection();

            //converting color to uint for storage in the data-layer cell
            int color = (int)colorD.Color.ToArgb();

            foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
            {
                SpreadsheetEngine.Cell dataCell = currSheet.GetCell(cell.RowIndex, cell.ColumnIndex);

                //add to undo
                pushUndoRedo.addCollection(new SpreadSheet.UndoRedo.UndoRedoCollection
                    ("color", currSheet.GetCell(cell.RowIndex, cell.ColumnIndex),
                    currSheet.GetCell(cell.RowIndex, cell.ColumnIndex).GetBGColor()));

                dataCell.SetBGColor(color);
                BackColorChanged += currSheet_PropertyChanged;
            }
            Undo_Redo.UndoPush(pushUndoRedo);
            reloadUndo();
            ReloadRedo();
        }