private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if ((dataGridView1.Focused) && (dataGridView1.CurrentCell.ColumnIndex == 0))
{
dtpInstallment.Location = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;
dtpInstallment.Visible = true;
if (dataGridView1.CurrentCell.Value != DBNull.Value)
{
// dtpInstallment.Value = DateTime.Today;
dtpInstallment.Value = (DateTime)dataGridView1.CurrentCell.Value;
// DateTime date = (DateTime)dataGridView1.CurrentCell.Value;
// dtpInstallment.Value = DateTime.Parse(date.ToString("dd/MM/yyyy"));
}
else
{
dtpInstallment.Value = DateTime.Today;
}
}
else
{
dtpInstallment.Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
In this datetime is throwing an exception…there is value in dataGridView1.CurrentCell.Value..but not able to convert to dtpInstallment.value which is DateTimePicker
It’s because the value your are parsing is not on the correct format. Try using
ParseExact