我在我的windows窗体上使用bindingsource当用户根据他的分期付款填写本金时,我计算他的每月金额。但问题是,当填写金额时我的文本更改事件触发两次,第二次principal
为空。我如何解决完美的计算工作。Datagridview textchange event fire两次
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]
它会触发在控制中的每一个文本变化 – V4Vendetta
没有在第一个功能我有控制,它将在本金量的单元格上工作 – Abhishek
@Abhishek我试过你的代码,它调用一次事件,而不是两次。 ... – vikas