Hi VS,
The reason for throwing the "object type cannot be converted to target type" exception is you are not able to store the String.Empty value or DBNull.Value for datetime value cell in a custom collection. But one way you can do this by replacing the string.Empty value in date column cell to DateTime.Min value in CurrentCellValidating event. and also you can handle the DrawCellDisplay event to show the empty text in a grid. Here is a code snippet
private void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell;
if( grid.Binder.InternalColumns[cc.ColIndex -1].MappingName == "Date")
{
if( cc.Renderer.ControlText == String.Empty )
{
cc.Renderer.ControlValue = DateTime.MinValue;
grid.Model[cc.RowIndex,cc.ColIndex].CellValue = DateTime.MinValue;
EmptyDateCell[GetHashCode(cc.RowIndex,cc.ColIndex)] = true;
grid.Binder.EndEdit();
}
else
{
EmptyDateCell[GetHashCode(cc.RowIndex,cc.ColIndex)] = false;
}
}
}
Please refer to the attached sample for more details.
DateTimeStringEmptyValue.zipBest Regards,
Haneef