Expression Editor for UWP
FlexGrid の列計算
Expression Editor の操作 > FlexGrid との統合 > FlexGrid の列計算

Expression Editor をグリッドと統合すると、FlexGrid の非連結列の列データを計算できます。

式を使用して FlexGrid の非連結列のデータを生成するために、C1FlexGrid クラスを継承して iSupportExpressions インタフェース実装するクラスを作成します。次に、計算された値を表示する新しい FlexGrid の非連結列にExpression Editorを追加します。

次の図に、式を使用して列計算を行う FlexGrid コントロールの例を示します。


 次のコードは、式を使用して FlexGrid 列の列計算を行う例を示します。

  1. 次のコードスニペットに示すように、C1FlexGrid を継承し、iSupportExpressions インタフェースを実装するクラスを作成します。
    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);
        }
               
        // ISupportExpressionsの使用
        public void SetCellValue(int row, string colName, object value)
        {
            this[row, colName] = value;
        }
        public ExpressionEditorCollection ExpressionEditors { get; }
        
    }
    
  2. ここで、次のコードスニペットに示すように、新しい FlexGrid の非連結列にExpression Editorを追加します。
    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);
    

先頭に戻る