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

Exception in group grid when trying to bind my data source

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)

2 Replies

HA haneefm Syncfusion Team July 30, 2007 06:12 PM UTC

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


HA Haishi July 30, 2007 06:48 PM UTC

Thanks! It works fine now.

Loader.
Live Chat Icon For mobile
Up arrow icon