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.
Marc Gravell - 16 Nov 2006 06:18 GMT
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;
}
mracuraintegra@gmail.com - 18 Nov 2006 01:21 GMT
WOO HOO! That did it. Thanks a bunch.
> Like so?
>
[quoted text clipped - 37 lines]
> public event EventHandler ValueChanged;
> }
Marc Gravell - 18 Nov 2006 21:43 GMT
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