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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Allowing invalid dates in a date field in GGC

Thread ID:

Created:

Updated:

Platform:

Replies:

51700 Nov 11,2006 03:19 AM UTC Nov 17,2006 06:34 AM UTC WinForms 3
loading
Tags: Grouping
Michael Lorenz
Asked On November 11, 2006 03:19 AM UTC

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

Administrator [Syncfusion]
Replied On 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

Michael Lorenz
Replied On 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

Administrator [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;