Search code examples
vb.netdatagridviewdecimalcell

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.


Solution

  • 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.