计算和更新控件不起作用 [英] Calculate and update the controls not working

查看:90
本文介绍了计算和更新控件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序需要进行计算并更新表格上的各种控件,因为数据会立即被捕获。



不工作,



纠正此问题的程序是什么?



谢谢







 受保护  void  txt_Tranche_TextChanged( object  sender,EventArgs e)
{

decimal mPrev = Convert.ToDecimal(txt_Actual_Disb.Text);
txt_Prev_Actual_Disb.Text = mPrev.ToString( N);

decimal mCurr = Convert.ToDecimal(txt_Tranche.Text);

decimal mTot = mCurr + mPrev;

txt_Actual_Disb.Text = mTot.ToString( N);

}

解决方案

首先,假设用户始终输入有效的十进制值:他赢了吨。并且一旦他没有,你的应用程序就会失败。

所以不要使用Convert.ToDecimal:改为使用decimal.TryParse,并将问题报告给用户。



除此之外,您还需要检查TextChanged事件是否正确连接:在方法开头添加断点并确保每次更改文本时都会调用该方法。

然后逐步完成该方法,看看每一步到底发生了什么。

我猜测从Convert.ToDecimal改变将解决你的问题。

The program needs to do the calculation and update the various controls on the form as data is captured instantly.

Not working,

What is the procedure to correct this?

Thanks



protected void txt_Tranche_TextChanged(object sender, EventArgs e)
      {

          decimal mPrev = Convert.ToDecimal(txt_Actual_Disb.Text);
          txt_Prev_Actual_Disb.Text = mPrev.ToString("N");

          decimal mCurr = Convert.ToDecimal(txt_Tranche.Text);

          decimal mTot = mCurr + mPrev;

          txt_Actual_Disb.Text = mTot.ToString("N");

      }

解决方案

First, you are assuming that the user always types valid decimal values: he won't. And as soon as he doesn't, your app fails.
So don't use Convert.ToDecimal: use decimal.TryParse instead, and report problems back to the user.

Other than that, you need to check that the TextChanged event is hooked up correctly: add a breakpoint at the start of the method and make sure that every time you change the text the method gets called.
Then step through the method and see exactly what is happening at each step.
I'm guessing that changing from Convert.ToDecimal will get rid of your problem.


这篇关于计算和更新控件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆