void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 2) { DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells[2]; string filename = cell.Value as string; if (!inUndoRedo) { SchemaDialogNewRow newRow = this.undoManager.Peek() as SchemaDialogNewRow; SchemaDialogEditCommand cmd = new SchemaDialogEditCommand(this.dataGridView1, this.items, row, filename); if (newRow != null) { this.undoManager.Pop(); // merge new row command with this edit command. cmd.IsNewRow = true; } Push(cmd); } } }