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.
Unfortunately, activation email could not send to your email. Please try again.

Exception in group grid when trying to bind my data source

Thread ID:

Created:

Updated:

Platform:

Replies:

65897 Jul 27,2007 01:23 PM Jul 30,2007 02:48 PM Windows Forms 2
loading
Tags: Grouping
Haishi
Asked On July 27, 2007 01:23 PM

This exception occures many times when I try to bind my data source. However the grid shows up eventually with no problem. However these exceptions cause my program to run very slow. The type I'm binding to doesn't contain a 'System.String[]' type at all. I wonder where did this come from.....

System.Reflection.TargetInvocationException: Property accessor 'Length' on object 'System.String[]' threw the following exception:'Object does not match target type.' ---> System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
--- End of inner exception stack trace ---
at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
at Syncfusion.Grouping.FieldDescriptor._GetValue(Record record)

haneefm [Syncfusion]
Replied On July 30, 2007 02:12 PM

Hi Stanley

Thank you for your update.

The reason is that you try to bind a IList with list of different derived class objects( obj1 and obj2). When you try to bind a BindingList(any List) with list of derived class objects, Grid will start binding the list of object of type same as the type of first item in the list. Then it will expect the remaining objects in the list to be of same type. You can bind the different derived class objects(derived from same base or abstract class) to the same Grid, you need to bind the grid to the BaseClass object, since derived class objects can be refered by its BaseClassType object. In your sample, you can achieve this by binding the empty BindingList to the grid in the form load or anywhere before populating the BindingList.

Here is the modified sample:
Modified_Sample

Best regards,
Haneef

Haishi
Replied On July 30, 2007 02:48 PM

Thanks! It works fine now.

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.

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.

;