473,396 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Displaying currency in a MaskedTextBox control

Hi,
I'm using C# to create a printable form. The data is coming from a XML
source that I load when the application starts. I have no problems loading
the data, but I am having a hard time figuring out the best way to display
currency in a field. I can use a MaskedTextBox, but it doesn't work in every
situation. Are there any good code samples to show how to resolve this
display issue? Thanks in advance!

Apr 3 '06 #1
2 6416
Hi,

Have you tried using the String.Format() method ?

as in :

Text1.Text = String.Format("{0:c}", price);

HTH,

Regards,

Cerebrus.

Apr 3 '06 #2
Thank you for the tip! I cleared my previous mask setting in the Mask
property and updated my code to include your code as well:

protected void FillForm(XmlDocument oXDoc, Form pForm)
{
// Fill in each control
int n = pForm.Controls.Count - 1;
for (int i = 0; i < n ; i++)
{
// set the text of the control
string strCtrl = pForm.Controls[i].Name;
string strType =
pForm.Controls[i].GetType().ToString().Substring(pForm.Controls[i].GetType().ToString().LastIndexOf(".") + 1);
XmlNodeList xmlNode = oXDoc.GetElementsByTagName(strCtrl);

// Make sure we have something to work with
if (xmlNode.Count > 0)
{
if (strType == "TextBox")
{
pForm.Controls[i].Text = xmlNode[0].InnerText;
}
else if (strType == "MaskedTextBox")
{
pForm.Controls[i].Text = String.Format("{0:c}",
xmlNode[0].InnerText);
}
}
}
}
Again, thanks for your help!
"Cerebrus" wrote:
Hi,

Have you tried using the String.Format() method ?

as in :

Text1.Text = String.Format("{0:c}", price);

HTH,

Regards,

Cerebrus.

Apr 4 '06 #3

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

Similar topics

0
by: Mauricio C Vidotto | last post by:
I have an application that use MaskedTextBox Control. This control has Mask property value 9999999.99 and I would like to add numeric values with 2 decimal places. However, if I set Text property...
5
by: pelcovits | last post by:
How do I get Access to put a blank in a report column (but not eliminate the record completely), when the field in question is currency format, and the value is zero? My understanding is that null...
3
by: Scott Gorman | last post by:
I have created a report in access. I had to add a text box to input a value for previous months balance. I have formatted to display with $ currency, and also with the " , " for thousand separator....
0
by: dumbo | last post by:
I do not succeed to modify the content of a MaskedTextBox control whose Property "OutputText" is in binding with field of type text of one table in database a MDB. The control has been generated...
1
by: .Net Sports | last post by:
the below itemdatabound function works , displays all the grand totals in the footer control of the datagrid: private void dglvboard_ItemDataBound(object sender,...
4
by: JotaO | last post by:
Hi! Can anyone tell me where can i find a free control (textbox style) that allows me to input numeric/currency data securelly? TIA JotaO
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
We have some dumb and lazy people here, so I need help. To fix the dumb part: We have placed MaskedTextBoxes on the forms so they will stop entering the information incorrectly. Now the lazy...
1
by: eljainc | last post by:
Hello, I am trying to utilize a MaskedTextBox control on my form. I would like the user to enter numbers only (i.e. 65000), I set the Mask property as 999999 and the PromptChar as space (it...
1
by: =?Utf-8?B?eXVyaWtz?= | last post by:
Hey, I'm building a business application that needs input of currency data. I looked a lot around google and friends for a good custom control to provide interactive validation and formatting of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.