" \r"在文本框输入中创建问题 [英] "\r" creating problem in textbox input

查看:93
本文介绍了" \r"在文本框输入中创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个12位数输入(数值)的文本框,根据这个数字,我将一些数据添加到datagrid中。当我第一次输入任何数字时,它可以正常工作,但是当我在向文本框输入任何新数字时向datagrid添加数据后,它只获得11位数。当我在调试模式下检查它时,我发现文本框有12位数字,包括开头的\ r。我不知道它来自何处并造成问题。



任何形式的帮助将不胜感激。谢谢



I've a textbox for input (numeric value) of 12 digits and on the basis of that number I add some data into datagrid. For the first time when I enter any number it works correctly, but after adding data to datagrid when I enter any new number to textbox, it only gets 11 digits. when I check it in debugging mode, I find textbox having 12 digits including "\r" at the start. I don't know from where its come and creates problem.

Any kind of help will be appreciated. Thanks

GroupedManifest grpManifest = new GroupedManifest();
grpManifest.manifestNumber = txtManifestNumber.Text; // get number from textbox
LayoutManifest.DataContext = grpManifest; // set relevant data to layout
manifestList.Add(LayoutManifest.DataContext as GroupedManifest); // add data to list
dataGridGroupedManifest.ItemsSource = null;
dataGridGroupedManifest.ItemsSource = manifestList; // set data to itemsource of datagrid

txtManifestNumber.Text = string.Empty;           // emtpy textbox
txtManifestNumber.Focus();// set focus on textbox





first时间这个代码工作得很好但是对于第二个数字txtManifestNumber只需要11个数字(例如12345678912)和txtManifestNumber.Text有\ r12345678912,它会在向datagrid添加数据时产生问题



first time this code works excellent but for the 2nd number txtManifestNumber only takes 11 digits (e.g 12345678912) and txtManifestNumber.Text has "\r12345678912" that creates issue on adding data to datagrid

推荐答案

我解决了我的问题的解决方案是..



我抓住textInputStart事件并在那里检查如果textbox.text包含\ rr 然后把它弄空,然后我给它分配新的输入。我仍然没有理由为什么在分配string.empty时仍然存在\ r但我的问题以这种方式解决了。
Solution that I got to solve out my problem is..

I catch textInputStart event and there I check that if textbox.text contains "\r" then make it empty and after that I assign it new input. Still I don't get the reason that why there remains "\r" when am assigning it string.empty but my problem is solved in this way.


这篇关于" \r"在文本框输入中创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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