简体   繁体   中英

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.

Thank you for the help.

The DefaultCellStyle.Format (and also cell format) operate only on the dataGridView display. When you get dvList.Rows(dvList.CurrentRow.Index).Cells.Item("Reg_Price").Value.ToString , you get the original cell, before formatting. You can use the vb.net Format function to format the numeric value for msgBox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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