/************************************************************* * 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(); }
void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; int col = e.ColumnIndex; string updateText; Cell sheetCell = mSheet.GetCell(row, col); try { // gather the updated text from the cell updateText = dataGridView1.Rows[row].Cells[col].Value.ToString(); } catch (NullReferenceException) { updateText = ""; } IUndoRedoCmd[] undos = new IUndoRedoCmd[1]; undos[0] = new RestoreTextCmd(sheetCell.Text, sheetCell.Name); // set the current selected cells text to the updated text sheetCell.Text = updateText; // since this function is related to cell text, we add a change in // cell text undo to the internal undo stack mSheet.AddUndo(new UndoRedoCollection(undos, "change in cell text")); // then set the value of the cell to the current cells internal value dataGridView1.Rows[row].Cells[col].Value = sheetCell.Value; UpdateToolStrip(); }
/************************************************************* * Function: Exec(Spreadsheet sheet) * Date Created: March 3, 2017 * Date Last Modified: March 3, 2017 * Description: Calls each one in the multiCmds * Return: Class multiCmds *************************************************************/ public multiCmds Exec(Spreadsheet sheet) { List <IUndoRedoCmd> cmd_list = new List <IUndoRedoCmd>(); foreach (IUndoRedoCmd cmd in m_cmds) { IUndoRedoCmd doCmd = cmd.Exec(sheet); cmd_list.Add(doCmd); } multiCmds mulcmds = new multiCmds(cmd_list.ToArray(), m_name); return(mulcmds); }
public void Add(IUndoRedoCmd toAdd) { this.cmds.Add(toAdd); }
public CmdCollection(IUndoRedoCmd Changed) { /* Constructor for passing in a single operation to restore to */ this.cmds = new List <IUndoRedoCmd>(); this.cmds.Add(Changed); }
public CmdCollection(IUndoRedoCmd Changed) { /* Constructor for passing in a single operation to restore to */ this.cmds = new List<IUndoRedoCmd>(); this.cmds.Add(Changed); }