Connecting Tech Pros Worldwide Forums | Help | Site Map

Expanded ReadOnly Array Elements in PropertyGrid

ljlevend2
Guest
 
Posts: n/a
#1: Nov 21 '05
If a property's type is an array and the property is exposed in a
PropertyGrid, then the property can be expanded so that the user can view and
edit the array elements. But, I've noticed that if the property is ReadOnly
then the expanded array elements can still be edited. I need to make the
elements ReadOnly if the property is ReadOnly. Is this possible?

Thank you,
Lance


Peter Huang [MSFT]
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi

Now I am researching the issue and I will update you with new information
ASAP.
Also I think you may try to post in the designtime specifed queue, so that
there will be more experienced designtime guys helps you.

microsoft.public.dotnet.framework.windowsforms.des igntime

Thanks for you understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Peter Huang [MSFT]
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi Lance,

I think it is by design, because the ReadOnly Property will return an
Array, while the Array is not readonly.
The workaround is changing the array to an ArrayList and returning the
array through the ArrayList.ReadOnly wrapper.

e.g.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'UserControl1
'
Me.Name = "UserControl1"
Me.strs.Add("Test")
Me.Size = New System.Drawing.Size(248, 240)

End Sub


Dim strs As New ArrayList
Public ReadOnly Property TestArray() As Object()
Get
Return ArrayList.ReadOnly(strs).ToArray()
End Get
End Property

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

ljlevend2
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Thank you for the idea. My hope was that I could inherit from
System.ComponentModel.ArrayConverter (or some other class) and modify its
behavior so that the expanded elements are ReadOnly. Do you know if that is
possible?

Also, please let me know if you would prefer to have me repost this thread
on the microsoft.public.dotnet.framework.windowsforms.des igntime group.

Thanks again,
Lance

Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi Lance,

For this issue, we will do some research into PointConverter class. We will
update you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#6: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi Lance,

I think this issue should be the same problem as another your post
"TypeConverters for Float Drawing Structures". I have posted a reply to you
in that thread, you may follow up there. I will keep up with you there.
Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

ljlevend2
Guest
 
Posts: n/a
#7: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


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.GetElement Type
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

Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#8: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi Lance,

Thanks for your feedback!!

Defaultly for jagged array, its second dimension should be a collection
editor dialog, while not in an expandable state. Can you show me how you
implement your jagged array and jagged array typeconverter? I suggest you
create a sample project for us to demonstrate your problem(you can attach
the project in the reply in newsgroup), then we can track your issue better
and quicker.

I will wait for your further reply. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#9: Nov 21 '05

re: Expanded ReadOnly Array Elements in PropertyGrid


Hi Lance,

Have you managed to create a sample reproduce project? Is your problem
resolved? Please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Closed Thread