DataGridView, TypeConverter & ITypeDescriptorContext

C

Caddzooks

Hi.

I've written some specialized TypeConverters that rely on attributes applied
to PropertyDescriptors for bound objects.

public MyClass
{

[TypeConverter(typeof(BearingConverter))]
[UnitSubType(UnitSubType.Bearing)]
public double Heading
{
{get...}
}
}

My 'BearingConverter; TypeConverter needs to look at the UnitSubType custom
attribute applied to the property in order for it to do its job.

When a property like this appears in the PropertyGrid, the custom
TypeConverter gets the PropertyDescriptor from the ITypeDescriptorContext
passed into its methods (like ConvertTo, CanConvertTo, and so on), which
allows it to access the custom attributes applied to the property.

But, when I bind the property to the column of a DataGridView, the
CustomTypeConverter is used, but when its methods are called, the
ITypeDescriptorContext parameter passed into those methods is always null.

So, the question is quite simply, given a DataGridView column that's bound
to a property, can the TypeConverter that's being used for the column access
the bound property's PropertyDescriptor and/or its attributes, and if so, how?

The thing that has me scratching my head is that the TypeConverter itself is
designated via the TypeConverter attribute applied to the property, and that
TypeConverter is being used, so the DataGridView is accessing the
PropertyDescriptor, but it is providing no 'context' for the TypeConverter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top