Hand Entering Date in DateTimePickerAdv

VS2003 - VB
SQL 2000
Essential Studio 3.3


In a grid, can a MonthCalendar control column, bound to a SQL date field, be formatted to accept a 6 or 8 digit numeric date (031607 or 03162007) and supply the slashes and century if necessary?

Thanks,
Tom

1 Reply

AD Administrator Syncfusion Team March 19, 2007 07:30 PM UTC

Hi Tom,

There is no property setting that will handle this problem. I think the simplest way to do this is to use the CurrentCellValidateString event in grid. Below is one way you can do it.

[VB]
Dim validFormats() As String = {"MM/dd/yy","MM/dd/yyyy"} ''''your acceptable formats.

Private Sub gridDataBoundGrid1_CurrentCellValidating(sender As Object, e As System.ComponentModel.CancelEventArgs)

Dim cc As GridCurrentCell = Me.gridDataBoundGrid1.CurrentCell
If cc.ColIndex = 3 Then
Try
Dim dt As DateTime = DateTime.ParseExact(cc.Renderer.ControlText, validFormats, Nothing, System.Globalization.DateTimeStyles.None)
cc.Renderer.Control.Text = dt.ToString()
Catch
cc.ErrorMessage="Invalid Date Format"
e.Cancel=true;

End Try
End If
End Sub ''''gridDataBoundGrid1_CurrentCellValidating

Please let me know if this helps.

Regards,
Haneef

Loader.
Up arrow icon