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

Allowing invalid dates in a date field in GGC

Hi,

My project's requirements say that we should allow users to enter incorrect information in GGC cells, and validate them when the user tries to save. I have a date column (the underlying datatype is DateTime), and it uses the MonthCalendar control to choose dates. It is, however, possible for the user to enter something like "abc" in this date field by hand. The problem is that when the user leaves the cell the GGC immediately pops up a message box saying that "abc is an invalid value for System.Date", highlights the row, puts an error icon on the cell and doesn't let the user exit the cell.

My question is, is it possible for me to:
a) Keep the underlying column as DateTime, but:
b) Turn off all of the normal validating behaviour and allow the user to leave the incorrect cell, while keeping the incorrect data in the cell.

The closest I've come so far, with various combinations of TableControlCurrentCellValidating, SaveCellFormattedText, etc. is that no exceptions are thrown and no error icon or message show up, but then the invalid cell value gets blanked out. I accomplish by having this line:
this.gridGroupingControl1.TableDescriptor.Columns["MonthCalendarAdv"].Appearance.AnyRecordFieldCell.CellValueType = typeof(System.String);

So, is there actually any way to accomplish what I'm trying to do?

Thanks,
Michael

3 Replies

AD Administrator Syncfusion Team November 13, 2006 12:33 PM UTC

Hi Michael,

The best way to do this would be to have an extra column in your DataTable say ‘HideMonthCalenderAdv’ to keep track of the MonthCalender cell invalid entries. You can handle the QueryCellFormattedText event to set the DisplayText of the MonthCalenderAdv from HideMonthCalenderAdv entries. Please refer this sample for the implementation

Sample : http://www.syncfusion.com/Support/user/uploads/DateTimeCell_ea5d8a7.zip

Best Regards,
Haneef


ML Michael Lorenz November 14, 2006 02:27 AM UTC

Hi Haneef,

Thanks for the example - a little tweaking gave me what I was looking for (the example doesn't update the date when you click on a date in the dropdown calendar).

Code snippet from gridGroupingControl1_TableControlCurrentCellCloseDropDown:
if( grecrow != null && grecrow.ParentRecord != null ) {
grecrow.ParentRecord.SetValue("HideMonthCalendarAdv" ,cc.Renderer.ControlValue);
try {
DateTime dt = DateTime.Parse( cc.Renderer.ControlValue.ToString() );
cc.Renderer.ControlValue = dt.ToString();
} catch {}

Not quite sure why this works, since I'm only getting the value and then setting it to what I just got, but this way the date updates immediately after a click on the calendar.

Thanks,
Michael


AD Administrator Syncfusion Team November 17, 2006 06:34 AM UTC

Hi Michael,

You can handle the TableControlCurrentCellCloseDropDown event and set the Renderer.ControlText property to DropDown value. Here is a code snippet to show this.

private void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, GridTableControlPopupClosedEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
if( cc.ColIndex == 5)
{
GridTableCellStyleInfo style = cc.Renderer.CurrentStyle as GridTableCellStyleInfo;
Element el = style.TableCellIdentity.DisplayElement;
GridRecordRow grecrow = el as GridRecordRow;

if( grecrow != null && grecrow.ParentRecord != null )
{
grecrow.ParentRecord.SetValue("HideMonthCalendarAdv" ,cc.Renderer.ControlValue);
cc.Renderer.ControlText = cc.Renderer.ControlValue.ToString() ;
}
}
}

Also refer the modified sample for more details.
http://www.syncfusion.com/Support/user/uploads/DateTimeCell_980bc944.zip

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon