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 / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

How do I set the datagrid column to currency format?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike L - 20 Dec 2005 20:29 GMT
Data in datagrid shows all numbers to the 1000th place. So, $3.00 is shown
3.0000

How do I set the datagrid column to currency format?

                           DataGridColumnStyle colStyle4 = new
DataGridTextBoxColumn();
                           dgts.GridColumnStyles.Add(colStyle4);
                           dgts.GridColumnStyles[4].Width = 75;
                           colStyle4.MappingName = dt.Columns[4].ColumnName;
"Jeffrey Tan[MSFT]" - 21 Dec 2005 02:13 GMT
Hi Cadel,

Thanks for your post.

We can set DataGridTextBoxColumn.Format to "c" to get the currency format.
For more information, please refer to DataGridTextBoxColumn.Format in MSDN
documentation.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Mike L - 21 Dec 2005 20:53 GMT
The example shows connecting to a table, but I'm connecting to a SP.

I get the error, "Object reference not set to an instance of an object."

                           DataGridColumnStyle colStyle4 = new
DataGridTextBoxColumn();
                           dgts.GridColumnStyles.Add(colStyle4);
                           dgts.GridColumnStyles[4].Width = 75;
                           DataGridTextBoxColumn myGridTextBoxColumn =
(DataGridTextBoxColumn)dgPrivileges.TableStyles["dbo.SALES_REVENUE"].GridColumnStyles["GROSS_FEE_AMOUNT"];
                           myGridTextBoxColumn.Format = "c";
                           colStyle4.MappingName = dt.Columns[4].ColumnName;

I have also tried using dt.TableName but recieved error, "Cannot convert
type 'string' to 'System.Windows.Forms.DataGridTextBoxColumn'

DataGridTextBoxColumn myGridTextBoxColumn =
(DataGridTextBoxColumn)dt.TableName;

> Hi Cadel,
>
[quoted text clipped - 11 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 22 Dec 2005 07:55 GMT
Hi Cadel,

Thanks for your feedback.

I think you may have some misunderstanding of winform databinding. DataGrid
will have no relation to do with database, it only can be bound to .Net
data object, such as DataTable, DataSet, ArrayList etc.... So it does not
care whether the data comes from SP or a SQL statement.

Normally, at DataGrid formatting side, you should first correctly get the
DataGridTextBoxColumn reference. The exception you got is
NullReferenceException, so I think myGridTextBoxColumn you got must be a
Null reference, which caused the problem, so please check this to ensure
that it gets the correct DataGridTextBoxColumn valid reference.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


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.