自定义格式或在数据绑定期间转换MaskedTextBox中的数据 [英] custom format or transform data in a MaskedTextBox during databinding

查看:105
本文介绍了自定义格式或在数据绑定期间转换MaskedTextBox中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在MaskedTextBox中显示除绑定数据(DataTable)之外的其他数据的方法.

更具体地说:DataTable包含一个DateTime列(DateOfBirth).每当年份为1900时,我都希望在MaskedTextBox中将其显示为空,同时将其保留在基础DataTable中,因为我将1900用作未知".

示例:数据表中的值:1900-10-09-[DataBinding]-> MaskedTextBox __- 10-09

当前,我正在使用BindingSource的CurrentItemChanged-Event来修改MaskedTextBox的文本属性.只要我简单地浏览DataTable,它就可以很好地工作.但是,一旦我开始编辑MaskedTextBox,1900又回来了.

如果我能以某种方式截获从DataRow传递到MaskedTextBox的值,而不是随后替换它,那就更好了.

还是有办法让MaskedTextBox显示1900为空?

我已经在stackoverflow上问过同样的问题,但是到目前为止,没有人提供新的答案-至少对于Windows窗体不是这样:
堆栈溢出

因此,如果有人知道这里的答案,将不胜感激!

非常感谢,并致以最诚挚的问候
-spitfire

I am looking for a way to display other data in a MaskedTextBox than the data it is bound to (DataTable).

More specifically: The DataTable contains a DateTime column (DateOfBirth). Whenever the year is 1900, I would like to display it as empty in the MaskedTextBox while keeping it in the underlying DataTable, because I use 1900 for "unknown".

Example: Value in the DataTable: 1900-10-09 --[DataBinding]--> MaskedTextBox __-10-09

Currently, I am using the CurrentItemChanged-Event of the BindingSource to modify the Text-property of the MaskedTextBox. That works nicely as long as I simply browse through the DataTable. However, as soon as I start editing the MaskedTextBox, 1900 is back.

It would be nicer if I could somehow intercept the value that is passed from the DataRow to the MaskedTextBox, instead of replacing it afterwards.

Or maybe there is a way to get the MaskedTextBox to display 1900 as empty?

I have already asked the same question at stackoverflow, but so far, nobody new an answer - at least not for Windows Forms:
stackoverflow

So, if somebody knows an answer here, it will be greatly appreciated!

Thank you very much and best regards
-spitfire

推荐答案

您是否尝试过Binding :: Format和Binding :: Parse? http://msdn.microsoft.com/en -US/library/system.windows.forms.binding_members(v = vs.80).aspx [
Have you tried Binding::Format and Binding::Parse ? http://msdn.microsoft.com/en-US/library/system.windows.forms.binding_members(v=vs.80).aspx[^]


这篇关于自定义格式或在数据绑定期间转换MaskedTextBox中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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