Click here to Skip to main content
11,929,950 members (34,772 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi all...i want to limit the decimal length of a datagridview column..

Please help me out
Posted 17-Nov-12 0:28am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this
for 2 places of decimal

double.Parse(string.Format("{0:0.00}", Eval("Name").ToString()))
DileepkumarReddy 17-Nov-12 6:12am
what is Eval and in which event should i try this...
pryashrma 17-Nov-12 6:59am
are you asking the query for 'GridView' control
DileepkumarReddy 17-Nov-12 7:14am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Alternate and easy way:
set the DataFormatString of Databound field
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567

for eg:
DataFormatString ="{0:F3}"

in aspx page design mode
single click on gridView1
then click on ">" of gridView1
then click on 'Edit Columns'
then select respective field and set 'DataFormatString'

you can also view the following link

please tell me if i m confusing you
DileepkumarReddy 17-Nov-12 7:04am
Actually i am working on windows app.
There is no property DataFormatString..
pryashrma 17-Nov-12 7:57am
does this line help you-

this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "F3";
pryashrma 17-Nov-12 7:48am
sorry can't help
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hey there,
Had a similar issue a while back...

VB Code to limit decimal:
Me.DataGridView1.Columns.Item(3).DefaultCellStyle.Format = "n2"

C# Code:
dataGridView2.Columns["Column_Name"].DefaultCellStyle.Format = "n2";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100