471,319 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

How do I set the datagrid column to currency format?

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;
Dec 20 '05 #1
3 11743
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 21 '05 #2
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;

""Jeffrey Tan[MSFT]"" wrote:
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 21 '05 #3
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jeff Cook | last post: by
1 post views Thread by J.B | last post: by
5 posts views Thread by Genojoe | last post: by
6 posts views Thread by KevinW | last post: by
1 post views Thread by cr113 | last post: by
5 posts views Thread by =?Utf-8?B?SnVsaWEgQg==?= | last post: by
reply views Thread by rosydwin | last post: by

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.