private void DataGridWorkBookForm_Load(object sender, System.EventArgs e) { this.dataGrid1.DataSource = GetARandomTable(); this.dataGrid2.DataSource = GetARandomTable(); this.dataGrid3.DataSource = GetARandomTable(); this.dataGrid4.DataSource = GetARandomTable(); this.dataGrid5.DataSource = GetARandomTable(); if (engine == null) { //Call this to reset static members in case other form is loaded first: Syncfusion.Calculate.CalcEngine.ResetSheetFamilyID(); //Create the engine: engine = new Syncfusion.Calculate.CalcEngine(this.dataGrid1); //Track dependencies required for auto calculations: engine.UseDependencies = true; //Register multiple ICalcData objects for cross sheet references: int sheetfamilyID = Syncfusion.Calculate.CalcEngine.CreateSheetFamilyID(); engine.RegisterGridAsSheet("DG1", this.dataGrid1, sheetfamilyID); engine.RegisterGridAsSheet("DG2", this.dataGrid2, sheetfamilyID); engine.RegisterGridAsSheet("DG3", this.dataGrid3, sheetfamilyID); engine.RegisterGridAsSheet("DG4", this.dataGrid4, sheetfamilyID); engine.RegisterGridAsSheet("DG5", this.dataGrid5, sheetfamilyID); } }
private void CalculateEngine() { //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(gridControl1); engine.ParseAndComputeFormula("=A1"); this.formulaNameCollection = GetFunctionNames(); this.functionCountLable.Text = "CALCULATE SUPPORTS " + formulaNameCollection.Count.ToString() + " FORMULAS."; this.formulaCombo.DataSource = formulaNameCollection; this.formulaCombo.SelectedIndex = 0; }
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 }
public MainWindow() { InitializeComponent(); this.gridpanel.Children.Add(gridControl1); Brush headerBrush = ColorHelper.CreateFrozenSolidColorBrush(128, Colors.CadetBlue); gridControl1.Model.HeaderStyle.Background = headerBrush; gridControl1.Model.HeaderStyle.Borders.All = new Pen(Brushes.White, 1); gridControl1.Model.TableStyle.Borders.All = new Pen(Brushes.White, 0); gridControl1.Model.HeaderStyle.Font.FontWeight = FontWeights.Bold; gridControl1.Model.TableStyle.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; gridControl1.Model.TableStyle.VerticalAlignment = System.Windows.VerticalAlignment.Center; gridControl1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); dt1.Add(new sample { A = "6", B = "58", C = "35", D = "0.01", E = "7/18/2011 7:45:05 AM", F = "7500", G = "-120000" }); dt1.Add(new sample { A = "25", B = "11", C = "25", D = "6", E = "TRUE", F = "4", G = "39000" }); dt1.Add(new sample { A = "0.15", B = "10", C = "23", D = "4", E = "FALSE", F = "3.5", G = "30000" }); dt1.Add(new sample { A = "0.75", B = "45.35", C = "47.65", D = "0.06", E = "8", F = "1.2", G = "21000" }); dt1.Add(new sample { A = "0.05", B = "17.56", C = "18.44", D = "10", E = "20", F = "0.908789", G = "37000" }); dt1.Add(new sample { A = "0.85", B = "16.09", C = "16.91", D = "-200", E = "3", F = "40", G = "46000" }); dt1.Add(new sample { A = "50", B = "2400", C = "15.20", D = "-500", E = "3", F = "1.5", G = "0.1" }); dt1.Add(new sample { A = "0.09", B = "300", C = "6", D = "0.068094", E = "8000", F = "10", G = "0.12" }); dt1.Add(new sample { A = "30", B = "10", C = "4", D = "0.01", E = "FLUID FLOW", F = "2", G = "#NULL!" }); dt1.Add(new sample { A = "125000", B = "STREET", C = "-200", D = "2", E = "$1000", F = "2000", G = "http://en.wikipedia.org/w/api.php?action=query&list=recentchanges&rcnamespace=0&format=xml" }); dt = ConvertToDatatable <sample>(dt1); dbdt.Add(new sample { A = "Tree", B = "Height", C = "Age", D = "Yield", E = "Profit", F = "Height", G = "13" }); dbdt.Add(new sample { A = "=\"=Apple\"", B = ">10", C = string.Empty, D = string.Empty, E = string.Empty, F = "<16", G = "12" }); dbdt.Add(new sample { A = "=\"=Pear\"", B = "", C = string.Empty, D = string.Empty, E = string.Empty, F = string.Empty, G = "11" }); dbdt.Add(new sample { A = "Tree", B = "Height", C = "Age", D = "Yield", E = "Profit", F = string.Empty, G = "8" }); dbdt.Add(new sample { A = "Apple", B = "18", C = "20", D = "14", E = "105.00", F = "-$10,000", G = "4" }); dbdt.Add(new sample { A = "Pear", B = "12", C = "12", D = "10", E = "96.00", F = "$2,750", G = "3" }); dbdt.Add(new sample { A = "Cherry", B = "13", C = "14", D = "9", E = "105.00", F = "4,250", G = "2" }); dbdt.Add(new sample { A = "Apple", B = "14", C = "15", D = "10", E = "75.00", F = "1-Jan-08", G = "1" }); dbdt.Add(new sample { A = "Pear", B = "9", C = "8", D = "8", E = "76.80", F = "1-Mar-08", G = "1" }); dbdt.Add(new sample { A = "Apple", B = "8", C = "9", D = "6", E = "45.00", F = "30-Oct-08", G = "1" }); dbDT = ConvertToDatatable <sample>(dbdt); dbfunction.Add("DCOUNT"); dbfunction.Add("DCOUNTA"); dbfunction.Add("DMIN"); dbfunction.Add("DMAX"); dbfunction.Add("DSUM"); dbfunction.Add("DPRODUCT"); dbfunction.Add("DAVERAGE"); dbfunction.Add("DSTDEV"); dbfunction.Add("DSTDEVP"); dbfunction.Add("DVAR"); dbfunction.Add("DVARP"); dbfunction.Add("DGET"); dbfunction.Add("FORMULATEXT"); dbfunction.Add("COUNTBLANK"); dbfunction.Add("PERCENTRANK.INC"); dbfunction.Add("PERCENTRANK.EXC"); dbfunction.Add("PERCENTRANK"); dbfunction.Add("XIRR"); gridControl1.Model.RowCount = dt.Rows.Count + 1; gridControl1.Model.ColumnCount = dt.Columns.Count + 1; gridControl1.Model.BaseStylesMap["Row Header"].StyleInfo.HorizontalAlignment = HorizontalAlignment.Center; gridControl1.Model.BaseStylesMap["Row Header"].StyleInfo.VerticalAlignment = VerticalAlignment.Center; Syncfusion.Calculate.CalcEngine.ResetSheetFamilyID(); engine = new Syncfusion.Calculate.CalcEngine(gridControl1); List <string> formulaNameCollection = GetFunctionNames(); var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static); var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static); var dpiX = (int)dpiXProperty.GetValue(null, null); var dpiY = (int)dpiYProperty.GetValue(null, null); if (dpiX > 100) { this.desc.Height = 120; this.sytx.Height = 60; t1.Width = 150; this.desc.Width = 300; this.sytx.Width = 300; this.res.Width = 300; this.res.FontSize = 21; this.cbx1.Height = this.t1.Height = 40; gridControl1.Model.RowHeights.DefaultLineSize = 35; gridControl1.Model.ColumnWidths.DefaultLineSize = 75; } else { this.desc.Height = 150; this.sytx.Height = 90; t1.Width = 220; this.desc.Width = 500; this.sytx.Width = 500; this.res.Width = 500; this.cbx1.Width = 230; this.cbx1.Height = this.t1.Height = 40; buttonAdv.Height = 40; gridControl1.Model.RowHeights.DefaultLineSize = 45; gridControl1.Model.ColumnWidths.DefaultLineSize = 85; } this.t1.KeyDown += new KeyEventHandler(t1_KeyDown); tempTextBlock.Text = "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"; this.functionCountLable.Text = "CALCULATE SUPPORTS " + formulaNameCollection.Count.ToString() + " FORMULAS."; this.cbx1.ItemsSource = formulaNameCollection; this.cbx1.CustomSource = formulaNameCollection; this.cbx1.SelectionChanged += new SelectionChangedEventHandler(cbx1_SelectionChanged); this.cbx1.SelectedIndex = 0; this.cbx1.SelectedIndex = formulaNameCollection.IndexOf("SUM"); this.t1.LostFocus += new RoutedEventHandler(t1_LostFocus); this.t1.GotFocus += new RoutedEventHandler(t1_GotFocus); this.t1.TextChanged += new TextChangedEventHandler(t1_TextChanged); }
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 }
private void gridDataBoundGridWorkBookForm_Load(object sender, System.EventArgs e) { this.gridDataBoundGrid1.DataSource = GetARandomTable(); this.gridDataBoundGrid2.DataSource = GetARandomTable(); this.gridDataBoundGrid3.DataSource = GetARandomTable(); this.gridDataBoundGrid4.DataSource = GetARandomTable(); this.gridDataBoundGrid5.DataSource = GetARandomTable(); 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.ThemesEnabled = true; this.gridDataBoundGrid1.Model.RowCount = 45; this.gridDataBoundGrid1.Font = new System.Drawing.Font("Segoe UI", 8.5F); this.gridDataBoundGrid2.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridDataBoundGrid2.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255))); this.gridDataBoundGrid2.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229))); this.gridDataBoundGrid2.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid; this.gridDataBoundGrid2.ForeColor = System.Drawing.Color.MidnightBlue; this.gridDataBoundGrid2.ThemesEnabled = true; this.gridDataBoundGrid2.Model.RowCount = 45; this.gridDataBoundGrid2.AllowProportionalColumnSizing = true; this.gridDataBoundGrid2.Font = new System.Drawing.Font("Segoe UI", 8.5F); this.gridDataBoundGrid3.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridDataBoundGrid3.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255))); this.gridDataBoundGrid3.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229))); this.gridDataBoundGrid3.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid; this.gridDataBoundGrid3.ForeColor = System.Drawing.Color.MidnightBlue; this.gridDataBoundGrid3.ThemesEnabled = true; this.gridDataBoundGrid3.AllowProportionalColumnSizing = true; this.gridDataBoundGrid3.Font = new System.Drawing.Font("Segoe UI", 8.5F); this.gridDataBoundGrid4.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridDataBoundGrid4.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255))); this.gridDataBoundGrid4.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229))); this.gridDataBoundGrid4.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid; this.gridDataBoundGrid4.ForeColor = System.Drawing.Color.MidnightBlue; this.gridDataBoundGrid4.ThemesEnabled = true; this.gridDataBoundGrid4.Model.RowCount = 25; this.gridDataBoundGrid4.AllowProportionalColumnSizing = true; this.gridDataBoundGrid4.Font = new System.Drawing.Font("Segoe UI", 8.5F); this.gridDataBoundGrid5.GridVisualStyles = Syncfusion.Windows.Forms.GridVisualStyles.Metro; this.gridDataBoundGrid5.Properties.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(239)), ((System.Byte)(255))); this.gridDataBoundGrid5.Properties.GridLineColor = System.Drawing.Color.FromArgb(((System.Byte)(208)), ((System.Byte)(215)), ((System.Byte)(229))); this.gridDataBoundGrid5.Model.Options.DefaultGridBorderStyle = GridBorderStyle.Solid; this.gridDataBoundGrid5.ForeColor = System.Drawing.Color.MidnightBlue; this.gridDataBoundGrid5.ThemesEnabled = true; this.gridDataBoundGrid5.Model.RowCount = 45; this.gridDataBoundGrid5.AllowProportionalColumnSizing = true; this.gridDataBoundGrid5.Font = new System.Drawing.Font("Segoe UI", 8.5F); if (engine == null) { //Create the engine: engine = new Syncfusion.Calculate.CalcEngine(this.gridDataBoundGrid1); //Track dependencies required for auto calculations: engine.UseDependencies = true; //Register multiple ICalcData objects for cross sheet references: int sheetfamilyID = Syncfusion.Calculate.CalcEngine.CreateSheetFamilyID(); engine.RegisterGridAsSheet("GDBG1", this.gridDataBoundGrid1, sheetfamilyID); engine.RegisterGridAsSheet("GDBG2", this.gridDataBoundGrid2, sheetfamilyID); engine.RegisterGridAsSheet("GDBG3", this.gridDataBoundGrid3, sheetfamilyID); engine.RegisterGridAsSheet("GDBG4", this.gridDataBoundGrid4, sheetfamilyID); engine.RegisterGridAsSheet("GDBG5", this.gridDataBoundGrid5, sheetfamilyID); } }