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 / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

DataGridView (.NET 2.0 Control) question about formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
g - 28 Dec 2005 01:59 GMT
Hi,

I have what I think should be a simple question about formatting a column in
my datagridview control as currency.

I used Visual Studio 2005 to add a column to my DataGridView control named
"Price".  I set the DefaultCellStyle.Format value to "C2" indicating that I
want the format of this cell to be currency with 2 decimal places.  However,
when I enter a number in the column it stays as I enter it.  For example, if
I entre a "1" it stays "1" rather than being formatted as "$1.00"

Doesn anyone know if I'm missing something?  I've read lots of documentation
at the MSDN2 site but I can't find anything to help me.  I've started to
work on custom formatting but it's seems to me that the control was designed
to allow for automatic formatting.

Thanks in Advance!
Christopher Reed - 28 Dec 2005 02:57 GMT
Try using only "C".  By default, currency values should only have 2 decimal
places.
Signature

Christopher A. Reed
"The oxen are slow, but the earth is patient."

> Hi,
>
[quoted text clipped - 14 lines]
>
> Thanks in Advance!
g - 28 Dec 2005 06:18 GMT
Hi Christopher,

Thanks for your response.  That doesn't do the trick however.

I added a form to allow the user to add data to the DataGridView rather than
editing it directly.  When i did this the correct columns were formatted as
currency.  This was because I added the data using the Rows.Add() method
which can handle decimal types directly.  Apparently, it's only formatted as
currency when it sees a number type and entering data directly into the
control doesn't qualify.
> Try using only "C".  By default, currency values should only have 2
> decimal places.
[quoted text clipped - 16 lines]
>>
>> Thanks in Advance!
Christopher Reed - 28 Dec 2005 06:21 GMT
You're right.  The format is for displaying the value, not while editing the
value.
Signature

Christopher A. Reed
"The oxen are slow, but the earth is patient."

> Hi Christopher,
>
[quoted text clipped - 26 lines]
>>>
>>> Thanks in Advance!
TT (Tom Tempelaere) - 29 Dec 2005 09:26 GMT
Hi,

> Hi Christopher,
>
[quoted text clipped - 6 lines]
> currency when it sees a number type and entering data directly into the
> control doesn't qualify.

You could subscribe to the ColumnChanging event of the DataTable and set the
ProposedValue in the DataColumnChangeEventArgs. I don't know if this is the
best way, but I think it can solve your problem.

Kind regards,
Signature

Tom Tempelaere.


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.