473,624 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ 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?

DataGridColumnS tyle colStyle4 = new
DataGridTextBox Column();
dgts.GridColumn Styles.Add(colS tyle4);
dgts.GridColumn Styles[4].Width = 75;
colStyle4.Mappi ngName = dt.Columns[4].ColumnName;
Dec 20 '05 #1
3 11991
Hi Cadel,

Thanks for your post.

We can set DataGridTextBox Column.Format to "c" to get the currency format.
For more information, please refer to DataGridTextBox Column.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."

DataGridColumnS tyle colStyle4 = new
DataGridTextBox Column();
dgts.GridColumn Styles.Add(colS tyle4);
dgts.GridColumn Styles[4].Width = 75;
DataGridTextBox Column myGridTextBoxCo lumn =
(DataGridTextBo xColumn)dgPrivi leges.TableStyl es["dbo.SALES_REVE NUE"].GridColumnStyl es["GROSS_FEE_AMOU NT"];
myGridTextBoxCo lumn.Format = "c";
colStyle4.Mappi ngName = dt.Columns[4].ColumnName;

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

DataGridTextBox Column myGridTextBoxCo lumn =
(DataGridTextBo xColumn)dt.Tabl eName;

""Jeffrey Tan[MSFT]"" wrote:
Hi Cadel,

Thanks for your post.

We can set DataGridTextBox Column.Format to "c" to get the currency format.
For more information, please refer to DataGridTextBox Column.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 misunderstandin g 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
DataGridTextBox Column reference. The exception you got is
NullReferenceEx ception, so I think myGridTextBoxCo lumn you got must be a
Null reference, which caused the problem, so please check this to ensure
that it gets the correct DataGridTextBox Column 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
7995
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 the column being built is called "$ Amount". If it hits this column, I use the DataFormatString = "{0:N}" All numbers are coming accross fine, if they are posative. For negative I need them to be the color red when displayed in the datagrid. I...
5
5555
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", XmlReadMode.InferSchema); grdXXXX.DataSource = ds; FormatGridColumns(grdXXXX, ds.Tables); // my routine below.
1
2308
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 and Currency format, all others are strings. I'd like to build one datagrid to handle this datagrid dynamically. I have it working now, all except the formatting of the 5th (Date) and 6th (Currency) columns. Since the headers for those...
0
1096
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 expression to {0:c} ********* Have the following code in the DataGrid1_UpdateCommand event handler
5
4561
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 dollar sign, the comma, and the decimal are included (i.e. $44,644.48) Managed to update the price column of the datagrid back to the database, as long as, the user doesn't delete the dollar sign (in the 0 position).
5
5901
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 changing the size of the form The code is at the following location in the January, 2004 help ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpref/html/frlrfSystemWindowsFormsDataGridClassTopic.ht You can also find it by doing a search for...
6
7110
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 currency in the editor, but I need to be able to do it in code. The column in question is a decimal in the dataset. I am sure there is an easy way to do this but I just can't figure it
1
1539
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 follows: DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 140 DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 125 DataGrid1.TableStyles(0).GridColumnStyles(0).Alignment = 0 DataGrid1.TableStyles(0).GridColumnStyles(1).Alignment = 1
5
2883
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, because I've got multiple currencies and currency format automatically picks up your local currency. I've searched everywhere for examples and can't find what I need. Has anyone got any help they could give me please?
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5565
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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 we have to send another system
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.