Quantcast
Viewing all articles
Browse latest Browse all 12583

DataGridview/Hierarchical BindingList - System.Reflection.TargetInvocationException

I'm implementing a datagridview on a Windows (4.0) Forms application. The grid is binding to a bindinglist of a class instance whose properties are themselves class instances consisting of 1 property. I have implemented a CustomTypeDescriptor and overrided the GetProperties method as below:

public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        try
        { 
            PropertyDescriptorCollection cols = base.GetProperties(attributes);

            PropertyDescriptor[] array = new PropertyDescriptor[cols.Count];
            for (int i = 0; i < cols.Count; i++ )
            {
                PropertyDescriptorCollection PDC = cols[i].GetChildProperties();
                array[i] = PDC[0];
            }

            PropertyDescriptorCollection newcols = new PropertyDescriptorCollection(array);
            return newcols;
        }
        catch (Exception ex)
        {
            log.Error(ex);
            return null;
        }
    }

The datagridview is set to autogeneratecolumns. When I put a breakpoint on the above function and set the DataSource property of the grid - the collection seems to be populating correctly. The column headers are also populated across the top of the grid. The following exception message is then repeatedly displayed until I stop the program:

"System.Reflection.TargetInvocationException: Property Accessor <> on object <> threw the following exception: 'Object Does Not match target type.'

Apart from GetProperties - are there other methods I need to override in order for the datagridview to understand a hierarchical bindinglist?

Thanks Jim



Intermediate Google goodies trawler...


Viewing all articles
Browse latest Browse all 12583

Trending Articles