且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将2个单元格相加并将结果添加到datagrid中的另一个单元格中

更新时间:2023-02-04 20:51:36

由于您正在使用数据表,因此我不会使用网格而是使用数据表进行计算。这样,演示文稿与数据分开。



数据表能够包含计算列。看一下 DataColumn.Expression Property [ ^ ]



因此公式可能类似于

Since you're using a data table, I wouldn't do the calculation using the grid but the data table. This way the presentation is kept separately from the data.

A data table has the ability to contain computed columns. Have a look at DataColumn.Expression Property[^]

So the formula could be something like
Dim totalColumn As DataColumn = New DataColumn
With totalColumn
    .DataType = System.Type.GetType("System.Int32")
    .ColumnName = "Total"
    .Expression = "TempoFinish-TempoStart"
End With