This is a migrated thread and some comments may be shown as answers.

[Solved] DataType on Column not displaying correctly

5 Answers 225 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 23 Apr 2009, 03:55 AM
Hi~2c~3cbr /~3e ~3cbr /~3e ~3cbr /~3e I want to set the DataType of a column to Double~2c such as~3cbr /~3e ~3cbr /~3e ~3cdiv style~3d~22border~3a 1px solid rgb~28127~2c 157~2c 185~29~3b overflow~3a auto~3b background-color~3a white~3b line-height~3a 100~25 ~21 important~3b font-family~3a courier new~3b font-size~3a 11px~3b~22 class~3d~22tFormatCodeBlock supportThreadCodeBlock~22~3e ~3ctable cellspacing~3d~220~22 cellpadding~3d~220~22 style~3d~22border-width~3a 0px~3b border-bottom~3a 0px solid rgb~28238~2c 238~2c 238~29~3b margin~3a 2px 0px~3b width~3a 99~25~3b border-collapse~3a collapse~3b background-color~3a rgb~28255~2c 255~2c 255~29~3b~22~3e ~3ccol style~3d~22border-bottom~3a 1px solid rgb~28247~2c 247~2c 247~29~3b font-family~3a courier new~3b font-size~3a 11px~3b padding-left~3a 10px~3b white-space~3a nowrap~3b~22 /~3e ~3ctbody~3e ~3ctr~3e ~3ctd~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3eSomeDataGrid.Columns.Add~28~3c/span~3e~3cspan style~3d~22color~3a blue~3b~22~3enew~3c/span~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3e~26nbsp~3bGridViewDataColumn~28~29~26nbsp~3b{~26nbsp~3bDataType~26nbsp~3b~3d~26nbsp~3b~28~3c/span~3e~3cspan style~3d~22color~3a blue~3b~22~3etypeof~3c/span~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3e~28~3c/span~3e~3cspan style~3d~22color~3a blue~3b~22~3edouble~3c/span~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3e~29~29~2c~26nbsp~3bHeaderText~26nbsp~3b~3d~26nbsp~3b~3c/span~3e~3cspan style~3d~22color~3a blue~3b~22~3e~22Target~22~3c/span~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3e~2c~26nbsp~3bUniqueName~26nbsp~3b~3d~26nbsp~3b~3c/span~3e~3cspan style~3d~22color~3a blue~3b~22~3e~22Target~22~3c/span~3e~3cspan style~3d~22font-size~3a 11px~3b~22~3e~26nbsp~3b}~29~3b~26nbsp~3b~3c/span~3e~3c/td~3e ~3c/tr~3e ~3c/tbody~3e ~3c/table~3e ~3c/div~3e ~3cbr /~3e ~3cbr /~3e The problem is~2c when I go to enter the data~2c I put in an example like 1.3~2c and moving away from the cell~2c it appears as ~221.29999995231628~22~3cbr /~3e ~3cbr /~3e Then when I go back to edit the cell~2c the value appears as ~221.3~22 until I leave the cell again~3cbr /~3e ~3cbr /~3e Similiarly~2c if I set the value as ~2233333333~22~2c when moved off the row~2c it appears as ~2233333332~22~3cbr /~3e ~3cbr /~3e ~3cbr /~3e Suggestions~3f

5 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 23 Apr 2009, 03:59 AM
I have no idea why the previous message failed... I will rewrite it....


I want to set some columns DataTypes as a Double

SomeDataGrid.Columns.Add(new GridViewDataColumn() { DataType = (typeof(double)), HeaderText = "Target", UniqueName = "Boundary.Target" });

If I enter the value "1.3" in edit mode, press enter, it appears as "1.2999999...", and if I enter "33333333", it appears as "33333332" when outside edit mode. Once I go back into edit mode, the numbers appear properly, until I exit back out of edit mode

Suggestions?
0
Accepted
Stefan Dobrev
Telerik team
answered on 23 Apr 2009, 01:10 PM
Hello Andrew,

This is a problem related to ContentPresenter control in Silverlight. If you just set the content to some double it will display it with precision till about the 15th symbol.

In your case you should explicitly set DataFormatString property of GridViewDataColumn:
DataFormatString = "{0:f3}" 

Hope this helps.

All the best,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andrew
Top achievements
Rank 1
answered on 23 Apr 2009, 11:51 PM
Excellent,

Thankyou
0
Andrew
Top achievements
Rank 1
answered on 23 Apr 2009, 11:53 PM
The funny text in the first post seems to happen when using the latest beta release for Firefox. No problems in IE
0
Andrew
Top achievements
Rank 1
answered on 24 Apr 2009, 12:04 AM
Deleted.
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or