We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Allow null value in date cell (GDBG)

After upgrading to version 6.2.0.32, I cannot delete a date from a GDBG field. When I delete a date and leave the cell, I get the message that the value is not a valid DateTime.
Property AllowDBNull of the corresponding DataColumn is set to true.

This also happens in your example GDBGcombos when for example I try to delete an order date from the order table.

What do I have to do?

Thanks in advance,
Martin


3 Replies

M. M.Tölle April 25, 2008 07:16 AM UTC

Hi,

the issue exists also for int cellvaluetype and i found no solution. This seems to be a bug!

bye
m.tölle



>After upgrading to version 6.2.0.32, I cannot delete a date from a GDBG field. When I delete a date and leave the cell, I get the message that the value is not a valid DateTime.
Property AllowDBNull of the corresponding DataColumn is set to true.

This also happens in your example GDBGcombos when for example I try to delete an order date from the order table.

What do I have to do?

Thanks in advance,
Martin





SR Sri Rajan Syncfusion Team April 28, 2008 11:50 PM UTC

Hi Martin,

You need to handle CurrentCellValidating and DrawCellDisplayText events to solve this issue. In currentCellValidating event, you should assign the Renderer.ControlValue to DateTime.MinValue if the ControlText is String.Empty and store the current cell location in Hashtable. In DrawCellDisplayText event, you need check the cell location with that Hashtable, if it presents then set e.DisplayText to String.Empty. Here is the sample code that shows this task.


void gridDataBoundGrid2_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
int RowIndex = e.Style.CellIdentity.RowIndex;
int ColIndex = e.Style.CellIdentity.ColIndex;
if (EmptyDateCell.Contains(GetHashCode(RowIndex, ColIndex)))
{
bool eValue = (bool)EmptyDateCell[GetHashCode(RowIndex, ColIndex)];
if (eValue)
{
e.DisplayText = String.Empty;
}
}
}
Hashtable EmptyDateCell = new Hashtable();
void gridDataBoundGrid2_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = grid.CurrentCell;
if (grid.Binder.InternalColumns[cc.ColIndex - 1].MappingName == "OrderDate" || grid.Binder.InternalColumns[cc.ColIndex - 1].MappingName == "RequiredDate" || grid.Binder.InternalColumns[cc.ColIndex - 1].MappingName == "ShippedDate")
{
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;
}
}
}
private string GetHashCode(int RowIndex, int ColIndex)
{
return "#" + RowIndex + "#-#" + ColIndex + "#";
}



Sample:
http://websamples.syncfusion.com/samples/Grid.Windows/F73126/main.htm

Please let me know if this helps.

Best Regards,
Srirajan




AD Administrator Syncfusion Team May 23, 2008 07:01 AM UTC

Hi Srirajan,

yes this helps, thank you very much.

Best Regards
Martin


Loader.
Live Chat Icon For mobile
Up arrow icon