动态计算2列积并给第三列赋值:
DGcountIndex 要赋值列的index
DGcountIndex1要计算列的index
DGcountIndex2要计算列的index
public static void DataGridCount(DataGridView DataGD, int DGcountIndex, int DGcountIndex1, int DGcountIndex2)
{
if (!DBNull.Value.Equals(DataGD.CurrentRow.Cells[DGcountIndex1].Value) & !DBNull.Value.Equals(DataGD.CurrentRow.Cells[DGcountIndex2].Value))
{
DataGD.CurrentRow.Cells[DGcountIndex].Value = Convert.ToSingle(DataGD.CurrentRow.Cells[DGcountIndex1].Value) * Convert.ToInt32(DataGD.CurrentRow.Cells[DGcountIndex2].Value);
}
}
在dataGridView_CellEndEdit事件中调用
如:计算第二列和第三列,给第四列赋值
DataGridCount(dataGridView1 , 3, 1, 2);
本文介绍了一个用于DataGridView的方法,可在CellEndEdit事件中调用该方法来动态计算两列的乘积并将结果赋值给另一列。此功能适用于需要实时更新计算结果的场景。
547

被折叠的 条评论
为什么被折叠?



