如何将2个单元格相加并将结果添加到datagrid中的另一个单元格中 [英] How do I sum 2 cells and add the result into another cell in datagrid
问题描述
大家好,
我很难过,不知道从哪里开始。所以任何帮助都将不胜感激。
我想将2个单元格的总和加在一起,并将结果插入到同一个数据网格中的新单元格中。
如下所示:
现有单元格1(速度完成)= 120 - 现有单元格2 - (速度开始)= 90新单元格(总计)= 30
这些单元格必须计算数据网格的每一行(不是列总数)。
我是显然是想要计算2个单元格的差异以反映节奏改善或速度降低,因此用户可以立即看到结果。
我可以得到一个导致Access数据库,但我想在数据网格中显示它而不使用Access查询表。我希望这些信息适用于表单加载。
提前感谢
Jason
Hi all,
I am stumped and have no idea where to start with this. So any help will be greatly appreciated.
I would like to add the sum of 2 cells together and insert the result into a new cell in that same datagrid.
Something like this below:
Existing Cell 1 (Tempo Finish) = 120 - Existing Cell 2 - (Tempo Start) = 90 New Cell (Total) = 30
These cells must calculate on each row of the datagrid (not a column total).
I'm obviously trying to calculate the difference of the 2 cells to reflect a tempo improvement or decrease in speed, so the und user can instantly see the result.
I can get a result in the Access database but I'd like to show this in the datagrid without using a Access query table. I want this information applied on form load.
thanks in advance
Jason
推荐答案
由于您正在使用数据表,因此我不会使用网格而是使用数据表进行计算。这样,演示文稿与数据分开。
数据表能够包含计算列。看一下 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
这篇关于如何将2个单元格相加并将结果添加到datagrid中的另一个单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!