0

在我的网格中,它显示了来自文本文件的所有小数位。

例如:网格中的权列有:1.000

但是当我尝试从中获取值时,DataGridView它只显示一个(1)而不是小数位。

Value = DgdOrderInfo.Rows(Intcnt).Cells("Weight").Value.ToString.Trim

让我知道如何获取所有数字值?

4

1 回答 1

0

Each cell in a DataGridView can have a DataGridViewCellStyle applied to it, which contains (among other things) a Format property that governs how the contents of that cell should be displayed. And an entire column or row can be assigned a default cell style that it uses for all of the cells in that row.

So probably what is happening is that you have a formatting string in use for your "Weight" column that formats all values with three trailing decimal places. When you retrieve the value, it is actually is just 1, but it is being displayed as 1.000 because of the formatting rules applied to all cells in that column.

If you want to retrieve this formatted value, you can do so by accessing the FormattedValue property, rather than the Value property. The necessary changes to your code are simple:

string value = DgdOrderInfo.Rows(Intcnt).Cells("Weight").FormattedValue.ToString.Trim

I also doubt very seriously that there is any need to call the Trim method on the return string.

于 2013-05-26T11:46:04.607 回答