views:

141

answers:

2

I have a datagridview in which one column contains a custom class, which I have set using:

dgvPeriods.Columns[1].ValueType = typeof(ExDateTime);

It is rigged up to display correctly by handling the CellFormatting event, but I'm unsure what event to handle for cell editing. In the absence of doing anything I get a FormatException as the datagridview tries to convert String to ExDateTime as I try to move focus out of the edited cell. I tried adding type conversion to my ExDateTime custom class:

public static implicit operator ExDateTime(string b)
{
    return new ExDateTime(b);
} 

But this this didn't work. I also tried handling the DataError event, but this seems to fire too late. The datagridview is not databound.

A: 

try handling the grid's CellValidating event

devnull
A: 

It turns out I need to handle the CellParsing event:

e.Value = new ExDateTime(e.Value.ToString());
e.ParsingApplied = true;
Ian Hopkinson