简体   繁体   English

从datagridview单元格获取值放入小数的问题

[英]Issue in getting the value from datagridview cell to put into decimal

This is my code for my button that will pop the value from the specific column. 这是我的按钮代码,将从特定列中弹出值。

dvList.Columns("Reg_Price").DefaultCellStyle.Format = "N2"

MsgBox(dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString)

My value in the column "Reg_Price" is 0, when I click the button with the code above, the output is 0 also, I want the output to be 0.00, but the code above the msgbox is not working. 我在“ Reg_Price”列中的值为0,当我单击上面代码的按钮时,输出也为0,我希望输出为0.00,但msgbox上方的代码不起作用。

Thank you for the help. 感谢您的帮助。

The DefaultCellStyle.Format (and also cell format) operate only on the dataGridView display. DefaultCellStyle.Format (以及单元格格式)仅在dataGridView显示屏上运行。 When you get dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString , you get the original cell, before formatting. 当获得dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString ,将获得原始单元格,然后进行格式化。 You can use the vb.net Format function to format the numeric value for msgBox. 您可以使用vb.net Format函数来格式化msgBox的数字值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM