structure as a property

S

Stivo

Take the structure existing structure Size, when you have a property Size
your click on Design Mode on the + and edit width and height.

But I tried to create a structure MyStructure
Structure MyStructure
public Key as long
public Text as String
end structure

but it is impossible to click on + to edit the members Key and Text, how can
I do it ?
 
H

haroldsphsu

If I understand correctly, you are trying to bind your structure to
the PropertyGrid. You'll have to expose Key and Text as public
properties (not fields), or implement a TypeConverter that returns Key
and Text as PropertyDescriptors and decorate your structure with
TypeConverter attribute. If you use Reflector to look at
System.Drawing.Size, you'll see this:

<Serializable, StructLayout(LayoutKind.Sequential),
TypeConverter(GetType(SizeConverter)), ComVisible(True)> _
Public Structure Size
...
End Structure

and the SizeConverter will look something like:

Public Class SizeConverter
Inherits TypeConverter
...

Public Overrides Function GetProperties(ByVal context As
ITypeDescriptorContext, ByVal value As Object, ByVal attributes As
Attribute()) As PropertyDescriptorCollection
Return TypeDescriptor.GetProperties(GetType(Size),
attributes).Sort(New String() { "Width", "Height" })
End Function

...

End Class

Hope this helps.

Harold
 
C

CMoya

Decorate the property with the following attributes.

<TypeConverter(GetType(ExpandableObjectConverter)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property MyProperty As MyStructure
....
End Property
 
C

CMoya

CMoya said:
Decorate the property with the following attributes.

<TypeConverter(GetType(ExpandableObjectConverter)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
_
Public Property MyProperty As MyStructure
...
End Property

Also, you probably need to docorate the structure decleration itself with
the following attributes:
<Serializable, StructLayout(LayoutKind.Sequential)>
 

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