By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Displaying currency in a MaskedTextBox control

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.