private void SingleDataGridForm_Load(object sender, System.EventArgs e) { #region create a DataTable this.dt = new DataTable("MyTable"); int nCols = 5; int nRows = 7; for (int i = 0; i < nCols; i++) { this.dt.Columns.Add(new DataColumn(string.Format("{0}", (char)((int)'A' + i)))); } Random r = new Random(); for (int i = 0; i < nRows; ++i) { DataRow dr = this.dt.NewRow(); for (int j = 0; j < nCols; j++) { if (j == 0) { dr[j] = (i + 1).ToString(); } else if (j == 1) { if (i == 0) { dr[j] = 1; } else { dr[j] = string.Format("=B{0} + {0}", i); } } else { dr[j] = r.Next(100).ToString(); } } this.dt.Rows.Add(dr); } #endregion //dataGrid1 is an instance of CalcDataGrid //Set the datasource to a DataTable: this.dataGrid1.DataSource = this.dt; //Call this to reset static members in case other form is loaded first: Syncfusion.Calculate.CalcEngine.ResetSheetFamilyID(); //Create a CalcEngine object, tie it to the DataGrid that implements ICalcData: engine = new Syncfusion.Calculate.CalcEngine(this.dataGrid1); //Register multiple ICalcData objects for cross sheet references: int sheetfamilyID = Syncfusion.Calculate.CalcEngine.CreateSheetFamilyID(); engine.RegisterGridAsSheet("SingleGrid", this.dataGrid1, sheetfamilyID); //Set the CalcEngine to track dependencies required for auto updating: engine.UseDependencies = true; //engine.IgnoreValueChanged = True; //Call RecalculateRange so any formulas in the data can be initially computed: engine.RecalculateRange(RangeInfo.Cells(1, 1, dt.Rows.Count, dt.Columns.Count), this.dataGrid1); //engine.IgnoreValueChanged = false; #region Adding a formula to the formula library - step 2 //Adding formulas to the CalcEngine Library: //Step 2: Call the AddFunction member of the Engine. //Add formula name Min to the Library: engine.AddFunction("Mymin", new Syncfusion.Calculate.CalcEngine.LibraryFunction(ComputeMymin)); #endregion }
private void SinglegridDataBoundGridForm_Load(object sender, System.EventArgs e) { #region create a DataTable this.dt = new DataTable("MyTable"); int nCols = 5; int nRows = 7; for (int i = 0; i < nCols; i++) { this.dt.Columns.Add(new DataColumn(string.Format("{0}", (char)((int)'A' + i)))); } Random r = new Random(); for (int i = 0; i < nRows; ++i) { DataRow dr = this.dt.NewRow(); for (int j = 0; j < nCols; j++) { if (j == 0) { dr[j] = (i + 1).ToString(); } else if (j == 1) { if (i == 0) { dr[j] = 1; } else { dr[j] = string.Format("=B{0} + {0}", i); } } else { dr[j] = r.Next(100).ToString(); } } this.dt.Rows.Add(dr); } #endregion this.gridDataBoundGrid1.DataSource = this.dt; this.gridDataBoundGrid1.AllowResizeToFit = false; this.gridDataBoundGrid1.DefaultColWidth = (int)DpiAware.LogicalToDeviceUnits(60.0f); this.gridDataBoundGrid1.DpiAware = true; //Call this to reset static members in case other form is loaded first: Syncfusion.Calculate.CalcEngine.ResetSheetFamilyID(); //Create a CalcEngine object, tie it to the gridDataBoundGrid that implements ICalcData: engine = new Syncfusion.Calculate.CalcEngine(this.gridDataBoundGrid1); //Set the CalcEngine to track dependencies required for auto updating: engine.UseDependencies = true; //Call RecalculateRange so any formulas in the data can be initially computed. //Code for all cells: //engine.RecalculateRange(RangeInfo.Cells(1, 1, dt.Rows.Count, dt.Columns.Count), this.gridDataBoundGrid1); //We only have formulas in column two, so just recalc that range: engine.RecalculateRange(RangeInfo.Cells(1, 2, dt.Rows.Count, 2), this.gridDataBoundGrid1); this.gridDataBoundGrid1.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridDataBoundGrid1.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255))); this.gridDataBoundGrid1.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229))); this.gridDataBoundGrid1.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid; this.gridDataBoundGrid1.ForeColor = System.Drawing.Color.MidnightBlue; this.gridDataBoundGrid1.Font = new System.Drawing.Font("Verdana", 8.5F); this.gridDataBoundGrid1.Model.RowCount = 25; this.gridDataBoundGrid1.AllowProportionalColumnSizing = true; #region Adding a formula to the formula library - step 2 //Adding formula to the CalcEngine Library. //Step 2: Call the AddFunction member of the engine. //Add formula name Min to the Library: engine.AddFunction("MyMin", new Syncfusion.Calculate.CalcEngine.LibraryFunction(ComputeMyMin)); #endregion }