Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / March 2006

Tip: Looking for answers? Try searching our database.

Currency Data in TextBoxes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MartinMCU - 30 Mar 2006 00:33 GMT
Hello All,

I am developing a database front end in C#, using Windows Forms as provided
by Visual Studio.NET 2005. I have several fields that are of the SQL Server
2005 datatype "money" and as such, I would like these fields to be displayed
as currency on my Windows Forms. I am trying to figure out how to format a
TextBox control to do this. I have seen references to the .ToString("C2")
method, however, I am not sure where this method is actually called.
Furthermore, I want these textboxes to be useable as input fields, and I am
not sure what the impact of the .ToString would be on that. I'm sure that
this isn't a difficult thhing to do, rather, I am just looking in the wrong
place. Any help would be appreciated. Thanks,

Matt
Kevin Spencer - 30 Mar 2006 01:37 GMT
currencyValue.ToString("C2")

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

> Hello All,
>
[quoted text clipped - 15 lines]
>
> Matt
MartinMCU - 30 Mar 2006 01:49 GMT
Since I've been dragging and dropping, I don't exactly have a
currencyValue... If I examine the properties for the control, say,
currencyTextBox, in the .Text property I see that there is a little icon,
which states that the value for the control comes from
"tblClientsBindingSource - curIncome" where curIncome is a money typed field
in the table tblClients.

Furthermore, will the .ToString work for propagating data back into the
table as a currency value? Thanks again,

Matt

> currencyValue.ToString("C2")
>
[quoted text clipped - 17 lines]
> >
> > Matt
Kevin Spencer - 30 Mar 2006 13:31 GMT
Hi Matt,

> Since I've been dragging and dropping, I don't exactly have a
> currencyValue...

Actually, since you've been dragging and dropping, and don't know how to
format the bound text box, what you don't have is a very good understanding
of what all that dragging and dropping actually does. In order to do the
kind of tweaking that you're talking about, you need to gain some
understanding of what Visual Studio has been doing for you, and behind your
back.

The first thing to understand is that all that dragging and dropping does is
to write code for you which you could write for yourself if you had more
time. The good thing about this is, you can also change that code. But
first, you need to know what that code is, and how it works. It is important
to understand that GUI tools are not a substitute for knowledge. They are
productivity tools, built to enable you to write your own code faster. They
can rough out some quick and dirty (but solid) code for you, and you have to
take over from there. In other words, it's time to roll up your sleeves and
do some homework!

Unfortunately, "dragging and dropping" doesn't tell me much about what
exactly you've done, nor what you've created. There are quite a few things
that can be done with data using Visual Studio's GUI tools. And since I
don't know what you've done, I don't know what you're looking at, and I
can't really go much further at this point than that. If I did know
something about what you're working with, in terms of code, I could help
out.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

> Since I've been dragging and dropping, I don't exactly have a
> currencyValue... If I examine the properties for the control, say,
[quoted text clipped - 34 lines]
>> >
>> > Matt
jimmy - 30 Mar 2006 16:58 GMT
martin,

you're looking for the format and parse events of the binding object...
the format event handles formatting the data that is about to be put
into the text box, and parse takes the information from the text box
and stuffs it back the datasource.  unfortunately, i've looked
everywhere and don't see someplace to specify their behavior at design
time.  which i'm finding very disappointing (i am looking at vs 2003
however)

with that said, i'll show you some code that hopefully will get you
started on the right track.  i'm just taking a stab at this one without
actually compilling it in VS, so let me know how it goes.

in the constructor for your form, try doing something like this:

Binding b = textBox.databindings["Text"]
b.Format += new ConvertEventHandler(this.currencyTextBox_Format)
b.Parse += new ConvertEventHandler(this.currencyTextBox_Parse)

then create the methods

private void currencyTextBox_Format(object sender, ConvertEventArgs e)
{
 e.value = e.value.toString("C2")
}

(something similar for parse if needed)...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.