Masked Text Box Screwing up my field value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a money field defined in a SQL Server 05 database with a value of
49.50. Also, it displays in SQL Server as 49.5000. I have a form in VB.NET
2005 and I'm using the new MaskedTextBox control in Visual Studio. I set the
Mask property for the text box to "$999.00".

The problem is when I run the form the text box displays "$495.00" and not
"$49.50" as one would expect. It it shifting the values left here. How do I
fix this?

Thanks in advance.
 
Hi Dave,

The MaskedTextBox class is an enhanced TextBox control that supports a
declarative syntax for accepting or rejecting user input. Generally
speaking, MaskedTextBox control is used in user input scenarios.

After we set the Mask property of a masked textbox control, the text in the
masked textbox is formatted according to the mask string. In your progam,
the previous text which is going to be displayed in the masked textbox is
'49.5000' and after the masked textbox's formatting, the text becomes
'$495.00'. Note that the character '.' in the previous text is removed
because this character isn't a valid number. And the character '.' in the
formatted text is the literal character defined in the mask string.

I don't think MaskedTextBox control is applicable to your scenario, since
you bind the masked textbox control to a data source to display the value
within the data source. I recommend you to use a textbox instead. As for
displaying the character '$' before the value from the data source, you
could handle the Format event of the Binding object that belongs to the
textbox.

The following is a sample.

public Form1()
{
this.textBox1.DataBindings[0].Format += new
ConvertEventHandler(Form1_Format);
}

void Form1_Format(object sender, ConvertEventArgs e)
{
e.Value = "$" + e.Value.ToString();
}

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for the response although it was not helpful. I had wanted to avoid
writing code. The Microsoft control should be able to handle this without
code but it cannot.

I finally opted to go with the Infragistics UltraMaskedEdit control and it
works beautifully and without code, as one would expect.

You might want to have the folks at Microsoft rewrite their MaskedTextBox
control so that it works with table data, especially money columns. A lot of
folks like myself use VB.NET for front-end development.

Also, I stated that I'm working in VB.NET, not C++ or C#.

--
Thank you,
Dave B.


Linda Liu said:
Hi Dave,

The MaskedTextBox class is an enhanced TextBox control that supports a
declarative syntax for accepting or rejecting user input. Generally
speaking, MaskedTextBox control is used in user input scenarios.

After we set the Mask property of a masked textbox control, the text in the
masked textbox is formatted according to the mask string. In your progam,
the previous text which is going to be displayed in the masked textbox is
'49.5000' and after the masked textbox's formatting, the text becomes
'$495.00'. Note that the character '.' in the previous text is removed
because this character isn't a valid number. And the character '.' in the
formatted text is the literal character defined in the mask string.

I don't think MaskedTextBox control is applicable to your scenario, since
you bind the masked textbox control to a data source to display the value
within the data source. I recommend you to use a textbox instead. As for
displaying the character '$' before the value from the data source, you
could handle the Format event of the Binding object that belongs to the
textbox.

The following is a sample.

public Form1()
{
this.textBox1.DataBindings[0].Format += new
ConvertEventHandler(Form1_Format);
}

void Form1_Format(object sender, ConvertEventArgs e)
{
e.Value = "$" + e.Value.ToString();
}

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Dave,

This is Yanhong, manager of MSDN Managed Newsgroup Support Team. Linda
discussed this issue with me and we invited some other members to review it
also.

It is a pity that MaskedTextBox control is not fit for your requirement
exactly yet. We have logged your requirement into our database for our
product team's reference. I am sorry that we didn't provide the sample code
in VB.NET. If you still need some VB.NET sample code, please feel free to
reply here and we will follow up.

At the same time, you can also submit your feedback to our connect web site
at:
http://connect.microsoft.com/site/sitehome.aspx?SiteID=210
By submitting suggestions and reporting bugs on Visual Studio 2005, the
.NET Framework 2.0, and developer Community Technology Previews (CTPs),
you're talking directly to the Microsoft development teams who build these
products. We are looking at continual improvement, and it's this kind of
feedback that let us know what things you're trying to do, that we haven't
yet exposed for you.

If you feel there is any we can do, please feel free to post here. Thanks
very much.

Sincerely,
Yanhong Huang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top