Jeffrey,
Thanks again for you help with "TypeConverters for Float Drawing
Structures". I applied the same technique (i.e., overriding
GetCreateInstanceSupported to return True) to a class that inherits from
ArrayConverter (e.g., MyArrayConverter) and the result is very close to the
desired behavior. But, I still have one issue and one question:
1. If a property is ReadOnly and the property type is a jagged array (e.g.,
Double()()) then the list of expanded elements that correspond to the first
dimension are disabled (i.e., ReadOnly), but expanded elements of the other
dimensions are enabled. Is there any way to make all of the array elements
disabled?
2. I've included my code for overriding CreateInstance in the modified
ArrayConverter. Can you please comment on whether or not there is a better
technique? Of particular concern is the For loop which is very inefficient.
For example, can it be assumed that the items in propertyValues.Values are in
the appropriate order so that propertyValues.Values.CopyTo can be used
instead of the For loop?
Public Overloads Overrides Function CreateInstance(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal propertyValues As
System.Collections.IDictionary) As Object
If ((context Is Nothing) OrElse (context.PropertyDescriptor Is
Nothing) OrElse (Not context.PropertyDescriptor.PropertyType.IsArray)) Then
Return Nothing
End If
If ((propertyValues Is Nothing) OrElse (propertyValues.Count = 0)) Then
Return Nothing
End If
'Create an array of the appropriate type and length.
Dim arrayElementType As System.Type =
context.PropertyDescriptor.PropertyType.GetElementType
Dim array As System.Array =
System.Array.CreateInstance(arrayElementType, propertyValues.Count) 'Return
value.
'Set the elements of the array.
Dim key As String
For i As Integer = 0 To array.GetUpperBound(0)
key = "[" & i.ToString & "]"
array.SetValue(propertyValues(key), i)
Next i
Return array
End Function
Thanks,
Lance