|
|
|
date: Tue, 27 May 2008 11:22:01 -0700,
group: microsoft.public.dotnet.framework.windowsforms.controls
back
RE: Formatting problem with MaskedTextBox
Hi Brad,
You are not saying if you bind against a string or a DateTime property, but
I assume you bind against a DateTime. For me your code works as expected,
but if I change the Culture from nb-NO to en-US I get the behaviour you are
describing with the initial value being 11/00/01__ (01.01.0001)
The problem is your formatstring. If you change it to
((MaskedTextBox)fldControl).DataBindings.Add("Text", this, "fieldName", true,
DataSourceUpdateMode.OnValidation, "", "MM/dd/yyyy");
You should see the correct value.
--
Happy Coding!
Morten Wennevik [C# MVP]
"brad" wrote:
>
> I am using a MaskedTextBox as shown in the code below. When I enter a date
> as 01/02/2003 and then move to another field it displays in the 12/20/03__
> It's interesting that the bound data column gets the correct value of
> 1/2/2003.
> I have tried different masks (00/00/00 and 09/09/0099) and setting or not
> settting the ValidatingType and other properties, but always get similar
> results.
>
> Code:
> ---
> fldControl = new MaskedTextBox("00/00/0000");
> // enter 01/02/2003; displays as 12/20/03__; sets as 1/2/2003
> ((MaskedTextBox)fldControl).PromptChar = '_';
> ((MaskedTextBox)fldControl).ValidatingType = typeof(System.DateTime);
> ((MaskedTextBox)fldControl).SkipLiterals = true;
> ((MaskedTextBox)fldControl).TextMaskFormat = MaskFormat.IncludeLiterals;
> ((MaskedTextBox)fldControl).DataBindings.Add("Text", data, fieldName, true,
> DataSourceUpdateMode.OnValidation, "", "d");
> ---
>
> brad
date: Wed, 28 May 2008 23:14:01 -0700
author: Morten Wennevik [C# MVP]
RE: Formatting problem with MaskedTextBox
Thanks. That's what I needed.
--
brad
"Morten Wennevik [C# MVP]" wrote:
> Hi Brad,
>
> You are not saying if you bind against a string or a DateTime property, but
> I assume you bind against a DateTime. For me your code works as expected,
> but if I change the Culture from nb-NO to en-US I get the behaviour you are
> describing with the initial value being 11/00/01__ (01.01.0001)
>
> The problem is your formatstring. If you change it to
>
> ((MaskedTextBox)fldControl).DataBindings.Add("Text", this, "fieldName", true,
> DataSourceUpdateMode.OnValidation, "", "MM/dd/yyyy");
>
> You should see the correct value.
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>
> "brad" wrote:
>
> >
> > I am using a MaskedTextBox as shown in the code below. When I enter a date
> > as 01/02/2003 and then move to another field it displays in the 12/20/03__
> > It's interesting that the bound data column gets the correct value of
> > 1/2/2003.
> > I have tried different masks (00/00/00 and 09/09/0099) and setting or not
> > settting the ValidatingType and other properties, but always get similar
> > results.
> >
> > Code:
> > ---
> > fldControl = new MaskedTextBox("00/00/0000");
> > // enter 01/02/2003; displays as 12/20/03__; sets as 1/2/2003
> > ((MaskedTextBox)fldControl).PromptChar = '_';
> > ((MaskedTextBox)fldControl).ValidatingType = typeof(System.DateTime);
> > ((MaskedTextBox)fldControl).SkipLiterals = true;
> > ((MaskedTextBox)fldControl).TextMaskFormat = MaskFormat.IncludeLiterals;
> > ((MaskedTextBox)fldControl).DataBindings.Add("Text", data, fieldName, true,
> > DataSourceUpdateMode.OnValidation, "", "d");
> > ---
> >
> > brad
date: Fri, 30 May 2008 13:27:01 -0700
author: brad
|
|