公式

来源:互联网 发布:potplayer播放器mac版 编辑:程序博客网 时间:2024/05/17 08:48

[C#]
private void CalcColumns(){
    DataColumn cPrice;
    DataColumn cTax;
    DataColumn cTotal;
    DataTable myTable = new DataTable ();
 
    // Create the first column.
    cPrice = new DataColumn();
    cPrice.DataType = System.Type.GetType("System.Decimal");
    cPrice.ColumnName = "price";
    cPrice.DefaultValue = 50;
        
    // Create the second, calculated, column.
    cTax = new DataColumn();
    cTax.DataType = System.Type.GetType("System.Decimal");
    cTax.ColumnName = "tax";
    cTax.Expression = "price * 0.0862";
        
    // Create third column.
    cTotal = new DataColumn();
    cTotal.DataType = System.Type.GetType("System.Decimal");
    cTotal.ColumnName = "total";
    cTotal.Expression = "price + tax";
   
    // Add columns to DataTable.
    myTable.Columns.Add(cPrice);
    myTable.Columns.Add(cTax);
    myTable.Columns.Add(cTotal);
    DataRow myRow;
    myRow = myTable.NewRow();
    myTable.Rows.Add(myRow);
    DataView myView = new DataView(myTable);
    dataGrid1.DataSource = myView;
 }

原创粉丝点击