PC Review


Reply
Thread Tools Rate Thread

Displaying currency in a MaskedTextBox control

 
 
=?Utf-8?B?SmFpbWUgUmlvcw==?=
Guest
Posts: n/a
 
      3rd Apr 2006
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!

 
Reply With Quote
 
 
 
 
Cerebrus
Guest
Posts: n/a
 
      3rd Apr 2006
Hi,

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

as in :

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

HTH,

Regards,

Cerebrus.

 
Reply With Quote
 
=?Utf-8?B?SmFpbWUgUmlvcw==?=
Guest
Posts: n/a
 
      4th Apr 2006
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.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. Problem with MaskedTextBox in DataGridView control AboutJAV@gmail.com Microsoft Dot NET Framework Forms 0 19th Jul 2007 10:22 PM
Using MaskedTextBox for currency values A.M-SG Microsoft Dot NET Framework Forms 3 3rd Feb 2006 07:03 AM
MaskedTextBox Control (.NET Framework 2.0) =?Utf-8?B?TWF1cmljaW8gQyBWaWRvdHRv?= Microsoft Dot NET 0 7th Oct 2005 04:00 PM
I can't modify a MaskedTextBox control in binding. =?Utf-8?B?ZHVtYm8=?= Microsoft VB .NET 0 17th May 2005 01:22 PM
I can't modify a MaskedTextBox control in binding. =?Utf-8?B?ZHVtYm8=?= Microsoft Dot NET Framework Forms 0 17th May 2005 01:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:56 PM.