473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

round data in datagird

hi,

When i access data from Access and place it in datagridview, the values are
not rounded off.
For example: In access i can see the value as 5.7 but when it is shown on
the grid it is 5.99999999
Does anyone know a method as to how to round it off to two decimal places
only.

I want to apply this roundoff property to specific columns only not to the
whole datagridview.

something like datagridview.columns(0).round(...).

TIA
Nov 21 '05 #1
2 1579
Hi,

Use a numberformatinfo. This is how to get a datagrid to display 1
digit after the decimal. Place this in your tablestyle for the grid.

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor =
cm.GetItemProperties()("Qty")

Dim ni As New System.Globalization.NumberFormatInfo

ni.NumberDecimalDigits = 1

Dim colQty As New DataGridTextBoxColumn(pd, "f")

With colQty

..MappingName = "Col1"

..HeaderText = "Qty"

..Width = 75

..FormatInfo = ni

End With

Ken

------------------------------
"Irfan" <ir***@asc-ltd.co.uk> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
hi,

When i access data from Access and place it in datagridview, the values are
not rounded off.
For example: In access i can see the value as 5.7 but when it is shown on
the grid it is 5.99999999
Does anyone know a method as to how to round it off to two decimal places
only.

I want to apply this roundoff property to specific columns only not to the
whole datagridview.

something like datagridview.columns(0).round(...).

TIA

Nov 21 '05 #2
Ken,

I havent created a custom grid, therefore i havent used
DataGridTextBoxColumn. I am
directly taking the column schema information from the database itself.

Am i right in saying that, if i havent created custom grid, i cant use
formatInfo property because it is available only in DataGridTextBoxColumn

Therfore, is their any other way.

Thanks for ur reply

Irfan

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:un*************@TK2MSFTNGP09.phx.gbl...
Hi,

Use a numberformatinfo. This is how to get a datagrid to display 1
digit after the decimal. Place this in your tablestyle for the grid.

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor =
cm.GetItemProperties()("Qty")

Dim ni As New System.Globalization.NumberFormatInfo

ni.NumberDecimalDigits = 1

Dim colQty As New DataGridTextBoxColumn(pd, "f")

With colQty

.MappingName = "Col1"

.HeaderText = "Qty"

.Width = 75

.FormatInfo = ni

End With

Ken

------------------------------
"Irfan" <ir***@asc-ltd.co.uk> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
hi,

When i access data from Access and place it in datagridview, the values
are
not rounded off.
For example: In access i can see the value as 5.7 but when it is shown on
the grid it is 5.99999999
Does anyone know a method as to how to round it off to two decimal places
only.

I want to apply this roundoff property to specific columns only not to the
whole datagridview.

something like datagridview.columns(0).round(...).

TIA

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter Scheurer | last post by:
Hi, we found some strange behavior when operating with floats and round(). The following simplified statement reproduces the problem. select 6.56 - round(convert(float, 6.56), 2) from...
0
by: Freddy | last post by:
I have 2 tables in a dataset. One of them is child to the other. In my dataset, I specify both default views to allowdelete = false My datasource table of the datagird is the master table...
6
by: Jef Driesen | last post by:
I need to implement a function to implement the rounding of floating point values. At the moment i have two different implementations, depending on the type of the return value (integer or double)....
0
by: timon | last post by:
I have create a Datagird in the window form. How can I set the column name in the datagird?
0
by: carlos perez | last post by:
Two thins There is a field called explanation. I need to detect if the field is empty the buttoncolumn must be active for that row if its already filled the user cant join more data. I have...
1
by: devo | last post by:
All- I need to format my datagrid so that each row within the datagrid shows two rows of data from the underlying dataset. Basically it is to reduce the length of the resulting html page. ...
1
by: Kiran | last post by:
Hi, Does any one know how to add a button to every row of a windows form datagird. Can anyone provide me some code on this. I have searched a lot but couldn't find any. I am posting this for...
1
by: Tull Clancey | last post by:
Hi All. I want to be able to change the font colour of certain rows in a Net.Datagird. The data source is a manually created data table within a set. I can format all the columns just the...
3
by: mukeshsrivastav | last post by:
thanks but sir writting query is not my problem.major problem i m finding is who to display quered data in datagrid.give me the syntex.datagrid is not allowing me show data searched through the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.