473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Masked Text Box Screwing up my field value

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.
--
Dave B.
Oct 25 '06 #1
3 9137
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.D ataBindings[0].Format += new
ConvertEventHan dler(Form1_Form at);
}

void Form1_Format(ob ject sender, ConvertEventArg s e)
{
e.Value = "$" + e.Value.ToStrin g();
}

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/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====

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

Oct 26 '06 #2
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 [MSFT]" wrote:
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.D ataBindings[0].Format += new
ConvertEventHan dler(Form1_Form at);
}

void Form1_Format(ob ject sender, ConvertEventArg s e)
{
e.Value = "$" + e.Value.ToStrin g();
}

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/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====

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

Oct 26 '06 #3
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/si...spx?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.

Oct 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5509
by: metridevkk | last post by:
Hi, I need to use a Masked Edit Control in my ASPX page. In VS.Net, I added the reference to MSMask.dll for my application & also added the MaskEdBox to the Toolbox. After adding the control to the web form, when I select the control & see its properties, I do not see the "Text" property. I also try to set the "Text" property in a javascript function, but cannot access it. Here is the code:
7
8698
by: DazedAndConfused | last post by:
Curently I manualy code keypress edits. i.e. allow only 3 digits before decimal and two digits after decimal in .NET. Is there an easy solution to mask text boxes? The MSMASK32.OCX from vb6 does not seem to be appropriate for a desktop application with textboxes not bound to a dataset, am I wrong? -- How time fly's when you don't know what you are doing!
0
1027
by: jean-michel bain-cornu | last post by:
Hi all, I'm trying to get the whole field selected when the caret arrives into a wx masked control. This is perfectly done with the program below. But if I comment out the line "r= dlg.ShowModal()", I get something different : the data within the field is no more correctly selected. Why ? And is there any solution ? If somebody have got an idea, I'd be delighted.
1
4238
by: Jeff Williams | last post by:
I want to use the masked text box to do the following 1. to allow a 4 digit number to be entered - mask 0000 2. to allow currency value to be entered - mask 0,000,000.00 in example 1 when I set the this.mtb_ref.text = 65 I get displayed 6500 but what I want displayed is 65 to the right of the box. I set the mtb to align right.
2
11354
by: james.czebiniak | last post by:
newbie to .net I have a masked textbox intended to display/input salary. The mask is 999,999 or ###,###. When I place the info from the database into the field it formats incorrectly. The salary is 75000. In the textbox it displays 750,00 What am I doing wrong?? ------------------------------------------------------------------------------------ Posted from WWWCoder.com (http://www.wwwcoder.com - The Web Developer's Resource site.
2
2109
by: gayano | last post by:
Hi, I'm using Visual studio 2005 pro Ver..]]] I have a Form named form1 textbox named txtName masked textbox (Date Masked) named txtMaskedDate and a button to add data named btnAdd dim name as string
3
3757
by: gayano | last post by:
Hi, I'm using Visual studio 2005 pro Ver..]]] I have a Form named form1 textbox named txtName masked textbox (Date Masked) named txtMaskedDate and a button to add data named btnAdd dim name as string
2
3549
by: creative1 | last post by:
Hi Everyone I switch between various fields on the form by using ENTER and TAB keys. I want to highlight existing value of a text fields when I get it focus. When we use combo, on getting focused on it it highlight the whole value present in it. Can I do this with text field and masked fields too? Thanks in advance.
0
1754
by: michels287 | last post by:
I have a masked textbox on my form. I have an onscreen keyboard with numbers only. The masked format for the masked textbox is: (###) ### - #### I want to make sure they enter the phone numbers properly, hence the mask. What I cannot seem to figure out is why can I not send the button captions (captions are the value of the number buttons, 1 through 9) into the masked box without an error? I get: Run Time Error '380'. Invalid...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.