structure as a property

  • Thread starter Thread starter Stivo
  • Start date Start date
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 ?
 
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
 
Decorate the property with the following attributes.

<TypeConverter(GetType(ExpandableObjectConverter)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property MyProperty As MyStructure
....
End Property
 
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)>
 
Back
Top