Ejemplo n.º 1
0
        private void DataGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (_changingTables || _inCellMouseEnter || !(tableList.SelectedItem is TableListEntry entry))
            {
                return;
            }

            var table = entry.Table;

            if (table == null || table.IsReadOnly)
            {
                return;
            }

            var cellValue      = dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            var newStringValue = cellValue as string;

            if (double.TryParse(newStringValue, out var value))
            {
                var edit = new EditCell(table, e.ColumnIndex, e.RowIndex, value);
                CommandHistory.Instance.Execute(edit);
            }

            DrawSideViews(e.ColumnIndex, e.RowIndex);
        }
        /// <summary>
        /// Invoked when the value of a data grid cell has changed.
        /// </summary>
        private void dataGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (this.changingTables || this.inCellMouseEnter)
            {
                return;
            }

            TableListEntry entry = this.tableList.SelectedItem as TableListEntry;

            if (entry == null)
            {
                return;
            }

            ITable table = entry.Table;

            if (table == null)
            {
                return;
            }

            if (table.IsReadOnly)
            {
                return;
            }

            object cellValue      = this.dataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
            string newStringValue = cellValue as string;

            double value;

            if (double.TryParse(newStringValue, out value))
            {
                EditCell edit = new EditCell(table, e.ColumnIndex, e.RowIndex, value);
                CommandHistory.Instance.Execute(edit);

                // The "smooth" button stops working if this code is enabled...

/*                foreach (DataGridViewCell cell in this.dataGrid.SelectedCells)
 *              {
 *                  // TODO: create an "EditSelectedCells" command, execute that instead, for better undo/redo
 *                  EditCell edit = new EditCell(table, cell.ColumnIndex, cell.RowIndex, value);
 *                  CommandHistory.Instance.Execute(edit);
 *                  cell.Value = value;
 *              }
 */
            }

            this.DrawSideViews(e.ColumnIndex, e.RowIndex);
        }