コード例 #1
0
        protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue)
        {
            SpreadsheetCell data = editingElement.DataContext as SpreadsheetCell;

            if (data != null)
            {
                data.Content = data.Tag.Value;
            }
        }
コード例 #2
0
        private void CheckForRecursion(SpreadsheetCell cell, DataTable dataTable, string cellNameToCheck)
        {
            if (cell.Tag.CellName.FullName == cellNameToCheck)
            {
                throw new RecursiveCellCallException("Infinity recursive loop detected!");
            }

            foreach (var consCellName in cell.Tag.DependentCells)
            {
                var consCell = dataTable.GetSpreadsheetCell(consCellName.Row, consCellName.Col);
                CheckForRecursion(consCell, dataTable, cellNameToCheck);
            }
        }
コード例 #3
0
        public static SpreadsheetCell GetSpreadsheetCell(this DataTable dataTable, int rowNum, int colNum)
        {
            int rowsCount = dataTable.Rows.Count;
            int colsCount = dataTable.Columns.Count;

            // Instead of throwing IndexOutOfRange exception, just return null
            if ((colNum < 0 || colNum > colsCount) || (rowNum < 0 || rowNum > rowsCount))
            {
                return(null);
            }

            SpreadsheetCell cell = dataTable.Rows[rowNum][colNum] as SpreadsheetCell;

            return(cell);
        }
コード例 #4
0
        protected override bool CommitCellEdit(FrameworkElement editingElement)
        {
            SpreadsheetCell data = editingElement.DataContext as SpreadsheetCell;

            if (data != null)
            {
                data.UpdateAllDependentCells();

                var formula = data.Content;
                data.Tag.Calculate(formula, data.Table);
                data.Content = data.Tag.Value;

                data.UpdateAllConsequentialCells();
            }

            return(base.CommitCellEdit(editingElement));
        }
コード例 #5
0
        protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
        {
            SpreadsheetCell data         = editingElement.DataContext as SpreadsheetCell;
            string          uneditedText = string.Empty;

            if (data != null)
            {
                uneditedText = data.Content;
                data.Content = data.Tag.Formula == string.Empty ? uneditedText : data.Tag.Formula;
            }

            // move focus to text field and select all text
            editingElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

            var contentPresenter = editingElement as ContentPresenter;
            var editingControl   = ExtendedDataGridExtensions.GetVisualChild <TextBox>(contentPresenter);

            editingControl.SelectAll();

            return(uneditedText);
        }
コード例 #6
0
        private void FillDefaultData(ExtendedDataGrid exGrid)
        {
            DataTable dataTable = new DataTable("DataTable" + this.NumberOfSheets);
            int rowsNum = 17;
            int colsNum = 13;

            for (int i = 0; i < colsNum; i++)
            {
                dataTable.Columns.Add(new DataColumn(SSColumns.ToString(i), typeof(SpreadsheetCell)));
            }

            for (int i = 0; i < rowsNum; i++)
            {
                var row = dataTable.NewRow();
                dataTable.Rows.Add(row);
                for (int j = 0; j < colsNum; j++)
                {
                    string cellName = SSColumns.ToString(j) + i;
                    row[j] = new SpreadsheetCell(string.Empty, dataTable, new SpreadsheetCellCustomInfo(new CellName(cellName, i, j)));
                }
            }

            this.DataTables.Add(dataTable);
            exGrid.ItemsSource = dataTable.DefaultView;
        }
コード例 #7
0
        /// <summary>
        /// Resize table by creating new and copying old values
        /// </summary>
        /// <param name="exGrid"></param>
        /// <param name="oldDataTable"></param>
        /// <param name="rowsNum"></param>
        /// <param name="colsNum"></param>
        private void ResizeTable(ExtendedDataGrid exGrid, DataTable oldDataTable, int rowsNum, int colsNum)
        {
            int boundRows = oldDataTable.Rows.Count < rowsNum ? oldDataTable.Rows.Count : rowsNum;
            int boundCols = oldDataTable.Columns.Count < colsNum ? oldDataTable.Columns.Count : colsNum;

            DataTable newDataTable = new DataTable(oldDataTable.TableName);

            for (int i = 0; i < colsNum; i++)
            {
                newDataTable.Columns.Add(new DataColumn(SSColumns.ToString(i), typeof(SpreadsheetCell)));
            }

            for (int i = 0; i < rowsNum; i++)
            {
                var row = newDataTable.NewRow();
                newDataTable.Rows.Add(row);
                for (int j = 0; j < colsNum; j++)
                {
                    string cellName = SSColumns.ToString(j) + i;
                    row[j] = new SpreadsheetCell(string.Empty, newDataTable, new SpreadsheetCellCustomInfo(new CellName(cellName, i, j)));
                }
            }

            // copy data
            for (int i = 0; i < boundRows; i++)
            {
                for (int j = 0; j < boundCols; j++)
                {
                    SpreadsheetCell cell = newDataTable.GetSpreadsheetCell(i, j);
                    SpreadsheetCell oldCell = oldDataTable.GetSpreadsheetCell(i, j);
                    cell.Content = oldCell.Content;
                    cell.Tag = oldCell.Tag;
                }
            }
            this.DataTables[this.CurrentSheetNumber] = newDataTable;
            
            // VERY VERY DIRTY HACK because nulling throws exception, dunno why
            try
            {
                exGrid.ItemsSource = null;
            }
            catch { }
            
            exGrid.ItemsSource = newDataTable.DefaultView;
        }
コード例 #8
0
        private void CheckForRecursion(SpreadsheetCell cell, DataTable dataTable, string cellNameToCheck)
        {
            if (cell.Tag.CellName.FullName == cellNameToCheck)
            {
                throw new RecursiveCellCallException("Infinity recursive loop detected!");
            }

            foreach (var consCellName in cell.Tag.DependentCells)
            {
                var consCell = dataTable.GetSpreadsheetCell(consCellName.Row, consCellName.Col);
                CheckForRecursion(consCell, dataTable, cellNameToCheck);
            }
        }