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

Unable to cast object of type ''System.Windows.Forms.Panel'' to type ''Syncfusion.Windows.Forms.Grid.GridControl''.

Recently we upgraded from v3.3 to v8.4 the following line of code used to work but now has a casting error.

((Syncfusion.Windows.Forms.Grid.GridControl)this.Calendar.Controls[0]).WantTabKey = false;

The calendar is a DateTimePickerADV.MonthCalendarForDateTimePickerAdv

Has something changed that you are no longer able to make this cast and if so is there some equivalent syntax that can accomplish using the WantTabKey properity?
Also this error only happens with I open the form in designer mode


1 Reply

MA Mahendran Syncfusion Team February 25, 2011 07:11 AM UTC

Hi Samantha ,

Thanks for your interest in Syncfusion Products.

To avoid this casting error you have to remove the below code from FormDesigner code and have to use in Form Load event. This is because the value of Controls[0] is cannot be recognized in designer mode. This works fine after initialization is done. The following code explains the same.

Code snippet [C #]

private void Form1_Load(object sender, EventArgs e)
{
if ((Syncfusion.Windows.Forms.Grid.GridControl)this.monthCalendarAdv1.Controls[0] is GridControl )
((Syncfusion.Windows.Forms.Grid.GridControl)this.monthCalendarAdv1.Controls[0]).WantTabKey = false;
}


Please let us know if you have any concerns.

Regards,
R.Mahendran



Loader.
Live Chat Icon For mobile
Up arrow icon