コード例 #1
0
ファイル: Spreadsheet.cs プロジェクト: KNatsuhara/Spreadsheet
        /// <summary>
        /// Sets the cell text in the cell grid.
        /// </summary>
        /// <param name="row">Row.</param>
        /// <param name="col">Column.</param>
        /// <param name="text">Text.</param>
        public void SetCellText(int row, int col, string text)
        {
            string newText;

            if (text == null)
            {
                newText = string.Empty;
            }
            else
            {
                newText = text;
            }

            string oldText;

            if (this.cellGrid[row, col].Text == null)
            {
                oldText = string.Empty;
            }
            else
            {
                oldText = this.cellGrid[row, col].Text;
            }

            UndoRedoText newCmd = new UndoRedoText(oldText, newText, ref this.cellGrid[row, col]);

            this.undo.Push(newCmd);
            this.cellGrid[row, col].Text = text;
        }
コード例 #2
0
        private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCell formCell = this.dataGridView1.CurrentCell;
            Cell             cell     = this.sheet.GetCell(e.RowIndex, e.ColumnIndex);

            if (formCell.Value != null)
            {
                string temp = cell.Text;
                cell.Text = formCell.Value.ToString();

                UndoRedoText command = new UndoRedoText(cell, temp, cell.Text);
                this.sheet.AddUndo(command);
            }
            else
            {
                formCell.Value = string.Empty;
            }
        }
コード例 #3
0
        /// <summary>
        /// Insert "I love C#" in 50 cells randomly
        /// Set every cell in Column B to "This is cell B#". where # number is the row number for the cell
        /// Set every cell in Column A to "=B#", A will have the same value as B.
        /// </summary>
        private void Button1_Click(object sender, EventArgs e)
        {
            Random rand = new Random();

            for (int i = 0; i < 50; i++)
            {
                int    t_row = rand.Next(0, 50);
                int    t_col = rand.Next(2, 26);
                string t_txt = this.sheet.GetCell(t_row, t_col).Text;
                this.sheet.GetCell(t_row, t_col).Text = "I love C#";
                UndoRedoText command = new UndoRedoText(this.sheet.GetCell(t_row, t_col), t_txt, this.sheet.GetCell(t_row, t_col).Text);
                this.sheet.AddUndo(command);

                string t_txt2 = this.sheet.GetCell(i, 1).Text;
                this.sheet.GetCell(i, 1).Text = "This is cell B" + (i + 1);
                UndoRedoText command1 = new UndoRedoText(this.sheet.GetCell(i, 1), t_txt2, this.sheet.GetCell(i, 1).Text);
                this.sheet.AddUndo(command1);

                string t_txt3 = this.sheet.GetCell(i, 0).Text;
                this.sheet.GetCell(i, 0).Text = "=B" + (i + 1);
                UndoRedoText command2 = new UndoRedoText(this.sheet.GetCell(i, 0), t_txt3, this.sheet.GetCell(i, 0).Text);
                this.sheet.AddUndo(command2);
            }
        }