我正在尝试在用户输入指定单元格时更改货币格式。默认情况下,货币格式为“$”,当用户在特定单元格中输入时,格式更改为“₹”。但它给我一个错误。
更改单元格值更改格式的代码:
private void dg_PDetails_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dg_PDetails.Rows)
{
if (row.Cells[6].Value != null)
{
var format = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
format.CurrencySymbol = "₹ ";
dg_PDetails.Columns["AmountProduct"].DefaultCellStyle.FormatProvider = format;
dg_PDetails.Columns["AmountProduct"].DefaultCellStyle.Format = "c";
}
else if (row.Cells[6].Value == null)
{
var formats = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
formats.CurrencySymbol = "$ ";
dg_PDetails.Columns["AmountProduct"].DefaultCellStyle.FormatProvider = formats;
dg_PDetails.Columns["AmountProduct"].DefaultCellStyle.Format = "c";
}
}
}