round data in datagird

I

Irfan

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
 
K

Ken Tucker [MVP]

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

------------------------------
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
 
I

Irfan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top