0

我在我的 Windows 窗体上使用 bindingsource 用户在根据他的分期付款填写本金时我计算他的每月金额。但问题是当填写金额时,我的文本更改事件触发两次,第二次设为principalnull。我怎样才能完美地解决该计算。

 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]
4

1 回答 1

0

尝试使用Datagridvirew.CellValueChanged, 替换您想要在tx_TextChanged事件中执行的任何操作。

于 2013-06-05T06:17:48.603 回答