473,324 Members | 2,417 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,324 software developers and data experts.

Formatting a bound textbox to show currency?

I am seriously at my wits' end here with this. I've got a textbox bound
to a money column in a database, but it shows up as a decimal value,
meaning that $9.25 shows up as 9.250000. ARRRRG.

Here's what I've tried:
* String.Format("{0:C}", txtCalcValue.Text) (guess this only works on
console...)
* Masked text box with ###.## mask
* txtCalcValue.Text = txtCalcValue.Remove(txtCalcValue.Length, 4)

I've also tried to create my own currency textbox control with masking,
but it didn't work much better than the masking above.

I've now spent 2.25 hours just trying to get this damnable textbox to
stop showing millionths of a cent! Any help would be appreciated.

Nov 16 '06 #1
3 6660
Like so?

Marc

using System;
using System.Windows.Forms;

class Program
{
static void Main()
{
MyData md = new MyData();
md.Value = 123.45M;
using (Form f = new Form())
using (TextBox tb = new TextBox())
{
f.Controls.Add(tb);
tb.DataBindings.Add("Text", md, "Value", true).FormatString
= "C";
f.ShowDialog();
}
}
}
class MyData
{
private decimal value;
public decimal Value
{
get { return this.value; }
set
{
if (Value != value)
{
this.value = value;
EventHandler handler = ValueChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
}
}
public event EventHandler ValueChanged;
}

Nov 16 '06 #2
WOO HOO! That did it. Thanks a bunch.
Marc Gravell wrote:
Like so?

Marc

using System;
using System.Windows.Forms;

class Program
{
static void Main()
{
MyData md = new MyData();
md.Value = 123.45M;
using (Form f = new Form())
using (TextBox tb = new TextBox())
{
f.Controls.Add(tb);
tb.DataBindings.Add("Text", md, "Value", true).FormatString
= "C";
f.ShowDialog();
}
}
}
class MyData
{
private decimal value;
public decimal Value
{
get { return this.value; }
set
{
if (Value != value)
{
this.value = value;
EventHandler handler = ValueChanged;
if (handler != null) handler(this, EventArgs.Empty);
}
}
}
public event EventHandler ValueChanged;
}
Nov 18 '06 #3
Glad it helped, and thanks for getting back.

(it does sometimes grate a little [not much] when you go to the trouble
of writing a detailed reply, and you never get to find out if a: it
worked / helped, b: it didn't work / fit for some reason, or c: they
never looked for replies).

Happy coding,

Marc

Nov 18 '06 #4

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

Similar topics

16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
2
by: CSDunn | last post by:
Hello, In an Access 2003 ADP Subform, I am trying to set the BackGround color of three textbox fields (LSScore, RScore, WScore) in the current record of the subform to zero (black) if the value of...
3
by: trint | last post by:
Ok, I have a textbox that I want to check as one types each charactor for Currency formatting, another one for Date formating. Any help is appreciated. Thanks, Trint
5
by: RR SPSCC | last post by:
I have a textbox bound to a dataview field. How can I format the value to display as currency? Thanks in advance.
1
by: Rich | last post by:
Hello, I have some datefields in a dataset (ds1). I bind some textbox controls on a windows form to these date fields in ds1, but I only want to see 01/01/2004 instead of 1/1/2004 8:00:00 AM. ...
1
by: Robert Boudra | last post by:
How do I control formatting of values in a textbox bound to a table in a dataset? For example, if I want to show dates only in short format or a certain number of decimal points in a floating...
10
by: Lyn | last post by:
Hi, I would like to make a bound text box not visible if it is empty (not just disable it). This option is not available from the standard conditional formatting feature (at least, not that I can...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all I've got a datagrid with column with the numeric format {0:F2}. However this format expression does not give the numbers comma separators, which I need. I can't use the currency format,...
0
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.