我在我的 Windows 窗体上使用 bindingsource 用户在根据他的分期付款填写本金时我计算他的每月金额。但问题是当填写金额时,我的文本更改事件触发两次,第二次设为principal
null。我怎样才能完美地解决该计算。
private void prol04DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox tx = e.Control as TextBox;
DataGridViewTextBoxCell cell = prol04DataGridView.CurrentCell as DataGridViewTextBoxCell;
if (tx != null && cell.OwningColumn == prol04DataGridView.Columns[5])
{
tx.TextChanged -= new EventHandler(tx_TextChanged);
tx.TextChanged += new EventHandler(tx_TextChanged);
}
}
这是我的文本更改事件
void tx_TextChanged(object sender, EventArgs e)
{
try
{
TextBox Principal = (TextBox)sender;
Prol04 _ded = (Prol04)prol04BindingSource.Current;
/* Here P is PrinciplAmount*/
P = Convert.ToDecimal(Principal.Text);
Installment = Convert.ToDecimal(prol04DataGridView.CurrentRow.Cells[6].Value);
mnthPay = P / Installment;
_ded.MonthlyAmount = mnthPay;
_ded.Instalments =Convert.ToInt32(Installment);
prol04DataGridView.Refresh();
}
catch (Exception ex)
{
throw (ex);
}
}
![Datagrid Where i perform event][1]