// ** ctor /// <summary> /// Initializes a new instance of a DataGridCalcEngine. /// </summary> /// <param name="grid">Grid that provides data for the engine.</param> public DataGridCalcEngine(DataGridCalc grid) { // save reference to parent grid _grid = grid; // parse multi-cell range references ($A2:B$4) IdentifierChars = "$:"; }
public Form1() { InitializeComponent(); // create DataTable used as grid storage _table = new DataTable(); for (int c = 0; c < 50; c++) { var colHeader = DataGridCalc.GetAlphaColumnHeader(c); _table.Columns.Add(colHeader.ToString(), typeof(object)); } for (int r = 0; r < 50; r++) { _table.Rows.Add(_table.NewRow()); } // add some formulas to the table for (int r = 0; r < _table.Rows.Count - 2; r++) { var row = _table.Rows[r]; for (int c = 0; c < _table.Columns.Count; c++) { row[c] = string.Format("={0}*{1}", r + 1, c + 1); } } // add a total row var totRowIndex = _table.Rows.Count - 1; var totRow = _table.Rows[totRowIndex]; for (int c = 0; c < _table.Columns.Count; c++) { totRow[c] = string.Format("=sum({0}:{1})", _grid.GetAddress(1, c), _grid.GetAddress(totRowIndex - 2, c)); } // bind table to grid _grid.DataSource = _table; // update address and status bar when selection changes _grid.SelectionChanged += _grid_SelectionChanged; // update content in formula bar _txtFormula.Validating += _txtFormula_Validating; _txtFormula.KeyPress += _txtFormula_KeyPress; // show list of available functions _lblFunctions.MouseDown += _lblFunctions_MouseDown; }
// ** ctor public CellRangeReference(DataGridCalc grid, CellRange rng) { _grid = grid; _rng = rng; }