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
close icon

Reg: GridControl monthcalendar

Hi, In my grid control, i have month calender cell. 1)CellType = "MonthCalendar"; 2)CellValueType = typeof(System.DateTime); 3)Format = "MM/dd/yyyy"; a. If user enters 01/01/2005 , it is comming as 01/01/2005, no issue. b.If users enters 1/1/2005, grid is throghing exception and also i getting error message box "1/1/2005 is valid value for datetime" Debug exception: System.FormatException: String was not recognized as a valid DateTime. at Syncfusion.Styles.ValueConvert.Parse(String s, Type resultType, IFormatProvider provider, String format, Boolean returnDbNUllIfNotValid) at Syncfusion.Styles.ValueConvert.Parse(String s, Type resultType, IFormatProvider provider, String format) at Syncfusion.Windows.Forms.Grid.GridCellModelBase.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.ApplyFormattedText(String text) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnValidate() catched at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnValidate() in :line 0 c. If user enters 15/25/2005(MM/dd/yyyy) also i am getting exception in debug mode. How do i handle all three problem, Please provide sample for that. Thanks, Anna

3 Replies

ST stanleyj Syncfusion Team January 20, 2006 04:33 PM UTC

Hi Anna, If you wish to enter any format of DateTime and expect to recognize it, then custom validation is to be done in CurrentCellValidating event. Here is a sample. c. This is the right, because 15 is not a valid month. Best regards, Stanley


AS Anna Srinivasan January 23, 2006 05:25 AM UTC

Hi, Thanks for your solution. point No c. Month is not valid, i should not get exception debug window. First enter wrong month, you will get message "Verfy the date format". Thats fine. After that click date time picker using mouse you will get following exception in debug window. System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.GetDayOfNNY(DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at System.DateTimeParse.ProcessTerminaltState(Int32 dps, DateTimeResult result, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider) at System.DateTime.Parse(String s) at Syncfusion.Windows.Forms.Grid.GridDropDownMonthCalendarCellRenderer.DropDownContainerShowingDropDown(Object sender, CancelEventArgs e) catched at Syncfusion.Windows.Forms.Grid.GridDropDownMonthCalendarCellRenderer.DropDownContainerShowingDropDown(Object sender, CancelEventArgs e) in :line 0 I dont want that error displayed in debug window. How do i avoid that or handle that. Apart from this issue every thing is working fine. Thanks, Anna


ST stanleyj Syncfusion Team January 23, 2006 07:16 AM UTC

Hi Anna, It is again the same Format Exception, resetting cc.Renderer.ControlValue this problem can be avoided. private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; if(cc.ColIndex == 2) { try { DateTime dt = DateTime.ParseExact(cc.Renderer.ControlText, ExpertFormat,culture,DateTimeStyles.AllowWhiteSpaces); cc.Renderer.ControlValue = dt; this.gridControl1[cc.RowIndex,2].CellValue = dt; cc.Renderer.CurrentStyle.ApplyFormattedText(cc.Renderer.ControlText); } catch(FormatException fe) { cc.Renderer.ControlValue = ""; MessageBox.Show("Verify Your Date Format "+fe.ToString(),"Validation",MessageBoxButtons.OK,MessageBoxIcon.Warning); e.Cancel = true; } } } Best regards, Stanley

Loader.
Live Chat Icon For mobile
Up arrow icon