ComponentOne Expression Editor for UWP
Working with Expression Editor / Integration with FlexGrid / Column Calculation in FlexGrid
In This Topic
    Column Calculation in FlexGrid
    In This Topic

    Expression Editor, when integrated with grid, allows calculating column data for unbound columns of FlexGrid.

    To allow expressions to be used for generating data for unbound columns of FlexGrid, you can create a class that inherits C1FlexGrid class and implements ISupportExpressions interface. Then add Expression Editor on unbound columns of the new FlexGrid, where you need to display calculated values.

    The following image exhibits FlexGrid control, demonstrating column calculation using expressions.


     The following code demonstrates column calculation on FlexGrid columns through expressions.

    1. Create a class that inherits C1FlexGrid and implements ISupportExpressions interface, as shown in the following code snippet.
      Public Class FlexGridEE
          Inherits C1FlexGrid
          Implements ISupportExpressions
      
          Public Sub New()
              MyBase.New()
              ExpressionEditors = New ExpressionEditorCollection(Me)
          End Sub
      
          ' ISupportExpressions
      
          Public Sub SetCellValue(row As Integer, colName As String,
                                  value As Object) Implements 
                     ISupportExpressions.SetCellValue
              Me(row, colName) = value
          End Sub
      
          Public Overloads ReadOnly Property ExpressionEditors()
                      As ExpressionEditorCollection Implements 
                 ISupportExpressions.ExpressionEditors
      
          Private Property ISupportExpressions_ItemsSource
          As IEnumerable Implements ISupportExpressions.ItemsSource
              Get
                  Return Me.ItemsSource
              End Get
              Set(value As IEnumerable)
                  Me.ItemsSource = value
              End Set
          End Property
      
      End Class
      
      public class FlexGridEE : C1FlexGrid, ISupportExpressions
      {
          
          public FlexGridEE() : base()
          {
              ExpressionEditors = new ExpressionEditorCollection(this);
          }
                 
          // Using ISupportExpressions
          public void SetCellValue(int row, string colName, object value)
          {
              this[row, colName] = value;
          }
          public ExpressionEditorCollection ExpressionEditors { get; }
          
      }
      
    2. Now, add expression editor on unbound columns of the new FlexGrid, as shown in the following code snippet.
      Dim c1ExpressionEditor1 As New C1ExpressionEditor()
      Dim c1ExpressionEditor2 As New C1ExpressionEditor()
      c1ExpressionEditor1.Expression = "[Price] + [Cost]"
      c1ExpressionEditor2.Expression = "[Price] * 0.8 + [Cost]"
      flexGrid.ExpressionEditors.Add("CustomField1", c1ExpressionEditor1)
      flexGrid.ExpressionEditors.Add("CustomField2", c1ExpressionEditor2)
      
      C1ExpressionEditor c1ExpressionEditor1 = new C1ExpressionEditor();
      C1ExpressionEditor c1ExpressionEditor2 = new C1ExpressionEditor();
      c1ExpressionEditor1.Expression = "[Price] + [Cost]";
      c1ExpressionEditor2.Expression = "[Price] * 0.8 + [Cost]";
      flexGrid.ExpressionEditors.Add("CustomField1", c1ExpressionEditor1);
      flexGrid.ExpressionEditors.Add("CustomField2", c1ExpressionEditor2);
      

    Back to Top