我有一个填充了数据的datagridview。数据是数字。我想得到某些单元格的值,将该值乘以60并将新值打印到单元格中,但我似乎只能得到一个字符串值。这就是我到目前为止所做的:
private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
double hrsToMins = (double.Parse(dgv.Rows[e.RowIndex].Cells["Hours"].Value.ToString())*60);
if (dgv.Columns[e.ColumnIndex].Name == "Hours")
{
if (dgv.Rows[e.RowIndex].Cells["Hours"].Value.ToString() != "0")
hoursToMins = Convert.ToDouble(e.Value);
}
}
这不会改变任何事情。我究竟做错了什么?
答案 0 :(得分:0)
这是有效的:
e.Value = Double.Parse(e.Value.ToString()) * 60;
// Converts the string to a double using the static Parse method
// and multiplies it by 60.
e.Value = (double.Parse(e.Value.ToString()));
// Converts the double back to a string using the ToString method