Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2006, 03:22 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting number in DataGridView not working!

I am trying to change the number format in a cell (a number is already there, entered by the user) of my DataGridView (unbound) after clicking a button, for example. Here is line of code in the button click event:

myDataGridView.Rows(0).Cells(0).Style.Format = "C2"

The problem is that the format (currency in this example) does not take effect.



 
Old July 27th, 2006, 05:37 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The cell-formatting does not work with currencies and I do not know why. However, I found that if the variable you are posting to that particular cell is not in currency format (even in string type), it will not format properly. I had to force a format into a string before I could get the cell to actuall format properly.

Plus, you may want to preset the cell on the initialization of the grid. Hope that helps you!

Rafo of LTSE
 
Old July 27th, 2006, 06:01 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your input. I had to do the following to make it work. The default ValueType is "Object" and none of the numeric formats are applied until changed to "Decimal". I had to convert the string to a numerical value (single) also to make it take effect.

With myDataGridView.Rows(0).Cells(0)
     .ValueType = GetType(Decimal)
     .Style.Format = "C2"
     .Value = CSng(.Value)
End With







Similar Threads
Thread Thread Starter Forum Replies Last Post
Number formatting / RegExp pierre.voisin Javascript 0 March 3rd, 2008 01:50 PM
Need Help - Bound DataGridView Formatting Problem mbetter .NET Framework 2.0 0 November 4th, 2005 08:46 PM
formatting number vkey XSLT 1 June 22nd, 2005 02:29 AM
formatting number dhol General .NET 2 February 24th, 2005 12:47 PM
Formatting a number eelisMX Pro VB.NET 2002/2003 7 January 28th, 2005 05:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.