C# 如何在c中将datagridview column1和column2添加到column3中#
我正在尝试将column1值添加到column2,并且必须插入column2 我的代码是 事件为手机请假C# 如何在c中将datagridview column1和column2添加到column3中#,c#,datagridview,add,C#,Datagridview,Add,我正在尝试将column1值添加到column2,并且必须插入column2 我的代码是 事件为手机请假 if (dgrVwEmp.Columns[dgrVwEmp.CurrentCell.ColumnIndex].Name == "ol") { int ol; int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex] .Cells["ol"].EditedFormatt
if (dgrVwEmp.Columns[dgrVwEmp.CurrentCell.ColumnIndex].Name == "ol")
{
int ol;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ol"].EditedFormattedValue.ToString(), out ol);
int leavs;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlLeaves"].Value.ToString(), out leavs);
int dys;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlWrkng"].Value.ToString(), out dys);
dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlLeaves"].Value = (ol + leavs).ToString();
dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlWrkng"].Value = (dys - ol).ToString();
}
当我第一次尝试像这样添加时,值正在添加并插入到第三个字段中,如果我返回到同一单元格,它将再次添加到已添加的字段中。我怎样才能正确地添加它。这是因为我在用手机打电话。是否有其他方法或其他事件来正确执行此操作也许您可以引入一个保存旧值的变量,当触发事件时,旧值将在添加新值的同时从
TTLEVES
单元格中减去。对于ttlWrkng
单元格,情况正好相反:
private int oldValue = 0;
private void dgrVwEmp_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (dgrVwEmp.Columns[dgrVwEmp.CurrentCell.ColumnIndex].Name == "ol")
{
int ol;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ol"].EditedFormattedValue.ToString(), out ol);
int leavs;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlLeaves"].Value.ToString(), out leavs);
int dys;
int.TryParse(dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlWrkng"].Value.ToString(), out dys);
dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlLeaves"].Value = (ol + leavs - oldValue).ToString();
dgrVwEmp.Rows[dgrVwEmp.CurrentCell.RowIndex]
.Cells["ttlWrkng"].Value = (dys - ol + oldValue).ToString();
oldValue = ol;
}
}
我不确定问题是否清楚。你需要一个写着“不要再计算”之类的标志吗。。这是最好的主意。但是我如何才能发现值被更改为计算