Class GridFormulaCellModel
This GridCellModel supports entering formulas in a grid cell. This support is provided through the Engine member of this class. Engine is a GridFormulaEngine.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Grid
Assembly: Syncfusion.Grid.Windows.dll
Syntax
public class GridFormulaCellModel : GridTextBoxCellModel, ISerializable, IDisposable
Remarks
The default behavior is that any cell whose CellType is GridFormulaCellModel will be interpreted as a formula cell provided the text in the cell starts with '='. So, for such cells you would enter formulas such as =A1+A2+A3 or =Sum(A1:A3), an an attempt would be made to parse and compute the entry.
Alternatively, you can use the Syncfusion.Windows.Forms.Grid.GridFormulaCellModel.formulaChar character to specify which cells of CellType GridFormulaCellModel are to be used as formulas. You set this formulaChar private property through the class constructor which passes this parameter. If you set this value to '\0', every cell of CellType GridFormulaCellModel will be treated as a formula.
The RefreshCells(Int32, Int32) method redraws all the formula cells that depend upon a particular cell. This method is called when the user changes a value that affects other formula cells.
The GetFormattedText(GridStyleInfo, Object, Int32) method is where the actual calculations are done, if necessary, through calls to the Engine methods. This method also conditionally parses the formula only if it has been modified since the previous parse.
Constructors
GridFormulaCellModel(GridModel)
Use this constructor to force all cells of CellType GridFormulaCellModel whose text begin with '=' to be regarded as holding formulas.
Declaration
public GridFormulaCellModel(GridModel grid)
Parameters
Type | Name | Description |
---|---|---|
GridModel | grid | The GridModel using this GridFormulaCellModel. |
GridFormulaCellModel(GridModel, GridFormulaEngine, Char)
Constructor for use with an existing GridFormulaEngine.
Declaration
public GridFormulaCellModel(GridModel grid, GridFormulaEngine engine, char formulaChar)
Parameters
Type | Name | Description |
---|---|---|
GridModel | grid | The GridModel using this GridFormulaCellModel. |
GridFormulaEngine | engine | An existing GridFormulaEngine. |
System.Char | formulaChar | Any GridFormulaCellModel beginning with this character will be treated as a formula. If you set this value to '\0', every cell of CellType GridFormulaCellModel will be treated as a formula. |
Remarks
Use this constructor if you want to use derived GridFormulaCellModel and GridFormulaCellRenderer classes that share a single GridFormulaEngine.
GridFormulaCellModel(GridModel, Char)
Only cells whose contents begin with formulaChar will be treated as a formula. Other cells of CellType GridFormulaCellModel will be treated as GridTextBoxCellModel. The character formulaChar is ignored for parsing and computing purposes.
Declaration
public GridFormulaCellModel(GridModel grid, char formulaChar)
Parameters
Type | Name | Description |
---|---|---|
GridModel | grid | The GridModel using this GridFormulaCellModel. |
System.Char | formulaChar | Any GridFormulaCellModel beginning with this character will be treated as a formula. If you set this value to '\0', every cell of CellType GridFormulaCellModel will be treated as a formula. |
GridFormulaCellModel(SerializationInfo, StreamingContext)
Initializes a new GridFormulaCellModel from a serialization stream.
Declaration
protected GridFormulaCellModel(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | An object that holds all the data needed to serialize or deserialize this instance. |
System.Runtime.Serialization.StreamingContext | context | Describes the source and destination of the serialized stream specified by info. |
Properties
CalculatingSuspended
Gets or sets a value indicating whether formulas are immediately calculated as dependent cells are changed.
Declaration
public bool CalculatingSuspended { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Use this property to suspend calculations while a series of changes are made to dependent cells either by the user or programmatically. When the changes are complete, set this property to false, and then call RecalculateRange to recalculate the affected range.
The implementation delegates this property to the Engine.CalculatingSuspended property.
Examples
Use this code to suspend, and then later resume, calculations.
//suspend calculations...
GridFormulaCellModel formulaModel = this.gridControl1.CellModels["FormulaCell"] as GridFormulaCellModel;
formulaModel.CalculatingSuspended = true;
....
//make changes, say to, cells in the GridRangeInfo.Cells(1,1,10,20).
....
//later resume calculations and refresh any cells that depend on GridRangeInfo.Cells(1,1,10,20)
GridFormulaCellModel formulaModel = this.gridControl1.CellModels["FormulaCell"] as GridFormulaCellModel;
formulaModel.CalculatingSuspended = false;
formulaModel.RefreshRange(GridRangeInfo.Cells(1,1,10,20));
'suspend calculations...
Dim formulaModel As GridFormulaCellModel = Me.gridControl1.CellModel("FormulaCell")
formulaModel.CalculatingSuspended = True
....
'make changes, say to, cells in the GridRangeInfo.Cells(1,1,10,20).
....
'later resume calculations and refresh any cells that depend on GridRangeInfo.Cells(1,1,10,20)
Dim formulaModel As GridFormulaCellModel = Me.gridControl1.CellModel("FormulaCell")
formulaModel.CalculatingSuspended = False
formulaModel.RefreshRange(GridRangeInfo.Cells(1, 1, 10, 2))
Engine
Gets GridFormulaEngine encapsulates all formula features. Use this object to add / remove library functions.
Declaration
public GridFormulaEngine Engine { get; }
Property Value
Type |
---|
GridFormulaEngine |
Methods
CreateRenderer(GridControlBase)
Overridden to return a GridFormulaCellRenderer class.
Declaration
public override GridCellRendererBase CreateRenderer(GridControlBase control)
Parameters
Type | Name | Description |
---|---|---|
GridControlBase | control | The grid control. |
Returns
Type | Description |
---|---|
GridCellRendererBase | returns a GridFormulaCellRenderer object. |
Overrides
GetFormattedText(GridStyleInfo, Object, Int32)
Triggers the parsing and computing of formulas.
Declaration
public override string GetFormattedText(GridStyleInfo style, object value, int textInfo)
Parameters
Type | Name | Description |
---|---|---|
GridStyleInfo | style | The GridStyleInfo object that holds cell information. |
System.Object | value | The value to format. |
System.Int32 | textInfo | textInfo is a hint who is calling, default is GridCellBaseTextInfo.DisplayText. |
Returns
Type | Description |
---|---|
System.String | Either the computed value or the raw formula text. |
Overrides
Remarks
Overridden to trigger the parsing and computing of formulas. The computed value is returned for non-editing cells. The raw formula text is returned when the cell is actively being edited.
GetObjectData(SerializationInfo, StreamingContext)
Implements the ISerializable interface and returns the data needed to serialize the cell model.
Declaration
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.SerializationInfo | info | A SerializationInfo object containing the information required to serialize the cell model. |
System.Runtime.Serialization.StreamingContext | context | A StreamingContext object containing the source and destination of the serialized stream. |
Overrides
OnModelDeserialization(Object, GridModel)
Called from GridModel implementation of IDeserializationCallback.OnDeserialization.
Declaration
protected override void OnModelDeserialization(object sender, GridModel model)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The source of the event. |
GridModel | model | The GridModel that was deserialized. |
Overrides
RecalculateRange(GridRangeInfo)
Recalculates any formula cells in the specified range.
Declaration
public void RecalculateRange(GridRangeInfo range)
Parameters
Type | Name | Description |
---|---|---|
GridRangeInfo | range | GridRangeInfo object that specifies the cells to be recalculated. |
Remarks
The implementation is delegated to Engine.RecalculateRange.
RecalculateRange(GridRangeInfo, Boolean)
Recalculates any formula cells in the specified range.
Declaration
public void RecalculateRange(GridRangeInfo range, bool forceCalculations)
Parameters
Type | Name | Description |
---|---|---|
GridRangeInfo | range | GridRangeInfo object that specifies the cells to be recalculated. |
System.Boolean | forceCalculations | Determines whether the calculation is performed immediately or delayed until the next time the cell is drawn. |
Remarks
The implementation is delegated to Engine.RecalculateRange.
RefreshCells(Int32, Int32)
This method forces any formula cell dependent upon the passed-in cell in the row and column to be recomputed. This method is called by the model whenever the contents of the passed-in cell is changed. For example, the user changing a single non-formula cell may require the recomputing of several additional formula cells. This method triggers the redrawing of these dependent cells.
Declaration
public void RefreshCells(int row, int col)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | row | Row index of the cell that was modified by the user. |
System.Int32 | col | Column index of the cell that was modified by the user. |
RefreshRange(GridRangeInfo)
Recalculates every cell that depends upon any cell in the passed-in range.
Declaration
public void RefreshRange(GridRangeInfo range)
Parameters
Type | Name | Description |
---|---|---|
GridRangeInfo | range | GridRangeInfo object to be refreshed. |
Remarks
Calls the Engine.RefreshRange.