468,483 Members | 2,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,483 developers. It's quick & easy.

Expanded ReadOnly Array Elements in PropertyGrid

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

Nov 21 '05 #1
8 4965
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.

Nov 21 '05 #2
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.

Nov 21 '05 #3
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

Nov 21 '05 #4
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.

Nov 21 '05 #5
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.

Nov 21 '05 #6
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

Nov 21 '05 #7
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.

Nov 21 '05 #8
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.

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by kaeli | last post: by
reply views Thread by Saurabh Mishra | last post: by
3 posts views Thread by Pol Bawin | last post: by
2 posts views Thread by Dave Wurtz | last post: by
reply views Thread by ljlevend | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.