Home - Forums-.NET - FlyGrid.Net (Windows Forms) - If user enters an invalid date time, how to catch that?

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

If user enters an invalid date time, how to catch that?
Link Posted: 12-Jul-2006 07:28
If I use a DateTimeColumn, and the user enters something that is not a valid date, for example 'abc', the grid simply does not allow the user to leave the field.

I would like to catch this case, show the user a message telling them it is not a valid date, and restore the old value.

How can this be done?
Link Posted: 12-Jul-2006 08:08
You can use FlyGrid.NodeCellChanging event to validate or correct input of data:
[C#]
private void dataGrid_NodeCellChanging(object sender, NodeBase node, int index, ref object value)
{  
  FlyGrid flyGrid = sender as FlyGrid;
  Column col = flyGrid.Columns.FieldMapColumnFromIndex(index);
  if (col is DateTimeColumn)
  {
    try
    {
      //validate data
      DateTime.Parse(value as string);
    }
    catch
    {          
      value = col.GetValue(node);//revert to current value;
      MessageBox(\"incorrect data\");
    }
  }
}


or you can override DateTimeColumn.SetValue to validate data in column.
Link Posted: 12-Jul-2006 08:20
Thanks, overriding SetValue is the type of thing I was looking for.