Click here to Skip to main content
15,896,063 members

custom format or transform data in a MaskedTextBox during databinding

spitfire_ch asked:

Open original thread
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
Tags: C#, Windows Forms, Data binding, Event, Formating

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900