增加Textbox_Textchanged +1 [英] Increase Textbox_Textchanged +1

查看:73
本文介绍了增加Textbox_Textchanged +1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本框中增加一个数字例如

在文本框中当我写下10页面加载时,数字应该是11

所以我想要增加+1



这是我的代码。这使得stackoverflow。洞计算机冻结。



  private   void  TextBoxKundnr_TextChanged( object  sender,EventArgs e)
{

int serialNo = Convert.ToInt32(TextBoxKundnr.Text);
serialNo ++;
TextBoxKundnr.Text = serialNo.ToString(CultureInfo.InvariantCulture);


}

}

解决方案

嗯...这很明显,不是吗?

你什么时候得到一个TextChanged事件?

答案:当你改变文本属性时。

所以...当您使用TextBox TextChanged事件更改TextBox 的文本属性 时,您希望接下来会发生什么?

正确:另一个TextChange事件。哪个也会改变Text,导致另一个TextChanged事件,直到你的整个计算机冻结试图跟上最终让TextChanged事件结束,或者它的堆栈空间不足......



不要这样做。

忽略这个问题,在用户编辑时更改文字不是一件好事,而且会严重烦扰有些人。


看起来像是一个常见问题背后的错误概念。那serialNo是一个标识符,不是吗?在表单上的其他文本框中输入的更多数据描述了该项目,不是吗?最终数据在数据库中出现。

所以正确的解决方案是:让数据库生成标识符(例如自动增量列)。只显示从数据库中检索到的数据的ID值(例如查看或编辑数据),如果您全部显示(该软件的用户的这种标识符的含义是什么?)。

I want to increase a number in a textbox for example
In the textbox when i write 10 the next time the page load the number should be 11
So i want to increase by +1

this is my code. this make a stackoverflow. the hole computer freezes.

private void TextBoxKundnr_TextChanged(object sender, EventArgs e)
        {

            int serialNo = Convert.ToInt32(TextBoxKundnr.Text);
            serialNo++;
            TextBoxKundnr.Text = serialNo.ToString(CultureInfo.InvariantCulture);
            
            
            }
            
        }

解决方案

Well...it's pretty obvious, isn't it?
When do you get a TextChanged event?
Answer: when your change the Text Property.
So...when you change the Text Property of a TextBox from with that TextBox TextChanged event, what would you expect to happen next?
Correct: another TextChange Event. Which will also change the Text, causing another TextChanged event, which will....until your whole computer freezes trying to keep up with finally getting a TextChanged event to end, or it runs out of stack space...

Don't do it.
Ignoring this problem, changing text while your user is editing it is not a friendly thing to do, and will seriously annoy some people.


Looks like a wrong concept behind a common problem. That serialNo is an identifier, isn't it? And further data entered in other textboxes on the form describe the item, don't they? And eventually the data is tored in a database.
So the correct solution is: have the database generating the identifier (e.g. autoincrement column). Only show an ID value for data which were retrieved from the database (e.g. viewing or editing data), if you show it all (what's the meaning of such an identifier for the user of the software?).


这篇关于增加Textbox_Textchanged +1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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