I am trying to change the currency format as the user enters in a specified cell. By Default the currency format is '$' and as the user enters in a particular cell the format changes to '₹'. But it is throwing me an error.
The code to change the format on cell value change:
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";
}
}
}