0

I am using bindingsource on my windows form Where user when fill in principal amount according to his installment i calculate his monthly amount .But problem is that when fill the amount my text change event fire two times and second time principal make null . How can i resolve that calculation work perfect .

 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);
             }

        }

this is my text change event

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]
zey
  • 5,939
  • 14
  • 56
  • 110
Abhishek
  • 299
  • 2
  • 5
  • 18

1 Answers1

0

Try using Datagridvirew.CellValueChanged, to replace the whatever you want to do in tx_TextChanged event.