473,664 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co lumns(0).round( ...).

TIA
Nov 21 '05 #1
2 1600
Hi,

Use a numberformatinf o. 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.Bindin gContext(DataGr id1.DataSource) ,
CurrencyManager )

Dim pd As System.Componen tModel.Property Descriptor =
cm.GetItemPrope rties()("Qty")

Dim ni As New System.Globaliz ation.NumberFor matInfo

ni.NumberDecima lDigits = 1

Dim colQty As New DataGridTextBox Column(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******** ******@tk2msftn gp13.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.co lumns(0).round( ...).

TIA

Nov 21 '05 #2
Ken,

I havent created a custom grid, therefore i havent used
DataGridTextBox Column. 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 DataGridTextBox Column

Therfore, is their any other way.

Thanks for ur reply

Irfan

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:un******** *****@TK2MSFTNG P09.phx.gbl...
Hi,

Use a numberformatinf o. 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.Bindin gContext(DataGr id1.DataSource) ,
CurrencyManager )

Dim pd As System.Componen tModel.Property Descriptor =
cm.GetItemPrope rties()("Qty")

Dim ni As New System.Globaliz ation.NumberFor matInfo

ni.NumberDecima lDigits = 1

Dim colQty As New DataGridTextBox Column(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******** ******@tk2msftn gp13.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.co lumns(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
12611
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 sysusers where name = 'public'; =========== -8.88178419
0
1230
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 and I allow navigation in my datagrid. In the master table, I cannot delete rows witch is good
6
4052
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). // Integer calculation (fast) int iround(const double x) { return (x>=0 ? static_cast<int>(x + 0.5) : static_cast<int>(x + 0.5) } // Floating point calculation (slow) double dround(const double x) {
0
991
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
1195
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 another column called STATUS, there are 3 statrus, maximum, minimu, average, if that column is MAXIMUM I must put another color to that field The code of the datagird is the following
1
1045
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. The ItemDataBound event on the datagird fires for each bound row which doesn't help me- does anyone have any ideas on how I can end up with my desired result- illustrated so fantastically below :)) ?
1
1060
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 the second time. Any help would be appreciated
1
1321
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 way I need but I can't find a way to change a row colour. Any help greatly appreciated.
3
1520
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 query.it show data in single field filtered mode. code which i m using is adodc1.recordset.filter="firstname like ' "& text1.text & "%'". but system does not take this adodc1.recordset.filter="firstname like ' "& text1.text & "%'and lastname like' "...
0
8437
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
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
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
8636
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
7375
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
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

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.