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

MonthCalendar CellValue is DateTime or String?

I have one cell of my essential grid set to display a DateTime with a cell type of "MonthCalendar". In one of my event handlers, the first time I went through the following line of code the CellValue returned a DateTime so this worked: object dtobj = gridPeriods[r,c].CellValue; dttm = (DateTime) dtobj; but the second time through, it was throwing an InvalidCastException, so on further inspection I found (to my surprise) that althrough the CellType was still MonthCalendar, the CellValue was now returning a string object. Am I doing something wrong here, or do I need to handle it like this? if ( dtobj is DateTime ) { dttm = (DateTime) dtobj; } else { dttm = DateTime.Parse ( (string) dtobj; ) }

1 Reply

AD Administrator Syncfusion Team April 19, 2004 07:36 PM UTC

Hi Steve, Try setting the CellValueType to DateTime to see if that helps. GridStyleInfo style = this.gridControl1[1,2]; style.CellType = "MonthCalendar"; style.CellValueType = typeof(DateTime); style.Format = "dd/MM/yy HH.mm.ss"; Regards, Jay N.

Live Chat Icon For mobile
Up arrow icon