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. 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;
}
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;
}
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Douglas |
last post by:
Gday,
How would I format a number so that:
TheValue = 32500
Displays in the TextBox as: $32,500.00
|
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...
|
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
|
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.
|
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. ...
|
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...
|
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...
|
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,...
|
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. ...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
|
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...
| |