Click here to Skip to main content
15,917,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I set a NumericUpDown control to display value as currency?
...as $12,345.09

What I have tried:

I have searched the internet but I couldn’t find anything on how to add currency to a NumericUpDown. My result so far is 12,345.09 …and I’m looking for $12,345.09

I'm using VB
Posted
Updated 12-Aug-16 22:13pm

1 solution

To do that, you have to create your own CurrencyUpDown control, and derive it from NumericUpDown.
1) Create a CustomControl called CurrencyUpDown
2) At the top of the Solution Explorer pane, click "Show all files".
3) Open the CurrencyUpDown branch of your project, and double click "CurrencyUpDown.Designer.vb"
4) Change the Inherits line from UserControl to NumericUpDown
5) Save and close the file.
6) Go to the Code view for the control, and add an override method:
VB
Protected Overrides Sub UpdateEditText()
    Text = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol & Value.ToString()
End Sub
 
Share this answer
 
Comments
Jack-tek460 13-Aug-16 15:25pm    
Just got home from work and your solution works beatify. I really appreciate your help and quick respond.
But now, I’m facing new problem; when I use up/down buttons it works as it should, but when I manually want to change the number it changes to previous value – it doesn’t hold the manually entered numbers.

Example:
1. Current value - $24.77
2. Clicked between “2” and “4” and added “9” (changed value shows - $294.77)
3. It comes back to $24.77 when I click on anything on my form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900