473,763 Members | 8,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Te xt) (guess this only works on
console...)
* Masked text box with ###.## mask
* txtCalcValue.Te xt = txtCalcValue.Re move(txtCalcVal ue.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 6683
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).FormatStr ing
= "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).FormatStr ing
= "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
25884
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
2853
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 a bound checkbox field (Spanish) on the current record is True, and to 16777164 if the value of the bound checkbox field is False. The Subform's Name property is 'frmMainScores'. The Source Object Property of the Subform is 'frmMainSubScores'....
3
4054
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
1458
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
9412
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. In a DateTimePicker control I can set a custom format("MM/dd/yyyy"). So when I iterate through ds1 with currency manager (cma) I see the correct date format in a DateTimePicker control. Is it possible to set a custom date format like that for...
1
1078
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 point number. Also, are there problems binding a DateTime picker control? When I did this, it kept thinking the value was Null when I tried to move to a different record, even though a date was visible in the control. Thanks, Bob
10
8657
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 find). I thought of calling a class module function via Expression Builder for the control. I have written a basic function, but don't seem to be able to pass the relevant arguments correctly. It seems to me that I need to pass two...
5
2891
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, because I've got multiple currencies and currency format automatically picks up your local currency. I've searched everywhere for examples and can't find what I need. Has anyone got any help they could give me please?
0
2503
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. In this table there are multiple columns that cannot be NULL, which, are bound to other controls (but they're not really important at this time). I create a new row via the currency manager like so: _currencyManager.AddNew() _currentRow =...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.