473,467 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 11976
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil | last post by:
Using C#, I am building my datagrid in my code behind due to the need to dynamically build the columns. In my Code I use an array to accomplish this and I also use an if statement to determine if...
5
by: Jeff Cook | last post by:
Hi I have a DataGrid that I am using to display a .xml file (that has a schema in a .xsd), like this:- ds.ReadXmlSchema(sDataPath + "Data.xsd"); ds.ReadXml(sDataPath + "Data.xml",...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
0
by: cwbp17 | last post by:
Have a datagrid that displays the price column in this format $12,400.00 from a table. Went to the Property Builder of the datagrid and selected the Price column and changed the Data formatting...
5
by: cwbp17 | last post by:
Hi all, Have a datagrid that displays the price column of a table. Went to the Datagrid's Property builder and set the 'Data Formatting expression' for the PRICE column to {0:c}, so that the...
5
by: Genojoe | last post by:
I am using code from Help with two exceptions. (1) I increased the number of sample rows from 3 to 20, and (2) I anchored the datagrid to bottom of form so that I can change the size of the grid by...
6
by: KevinW | last post by:
I need to format a currency column in a datagrid. The line I have tried is: Me.DataGrid1.TableStyles(0).GridColumnStyles(3).ToString.Format("#,##0.00") It does not work. I can format the...
1
by: cr113 | last post by:
How do I format text in datagrid column? I have a column of currency values and I want them all to display with 2 decimal points (XXX.XX). I figured out how to set the width and alignment as...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all I've got a datagrid with column with the numeric format {0:F2}. However this format expression does not give the numbers comma separators, which I need. I can't use the currency format,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.