PC Review


Reply
Thread Tools Rate Thread

structure as a property

 
 
Stivo
Guest
Posts: n/a
 
      21st Dec 2007
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 ?
 
Reply With Quote
 
 
 
 
haroldsphsu@gmail.com
Guest
Posts: n/a
 
      22nd Dec 2007
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

On Dec 21, 2:04*pm, Stivo <St...@discussions.microsoft.com> wrote:
> 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 ?


 
Reply With Quote
 
CMoya
Guest
Posts: n/a
 
      29th Dec 2007
Decorate the property with the following attributes.

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


"Stivo" <(E-Mail Removed)> wrote in message
news:C96693C0-9170-4040-8E2C-(E-Mail Removed)...
> 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 ?


 
Reply With Quote
 
CMoya
Guest
Posts: n/a
 
      29th Dec 2007
"CMoya" <(E-Mail Removed)> wrote in message
news:09E0237F-67A3-47F9-8CE6-(E-Mail Removed)...
> 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)>


 
Reply With Quote
 
Robbe Morris - [MVP] C#
Guest
Posts: n/a
 
      30th Dec 2007
I'd take a long look at this approach and not worry about decorating
your class:

http://www.eggheadcafe.com/tutorials...d-control.aspx

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx



"Stivo" <(E-Mail Removed)> wrote in message
news:C96693C0-9170-4040-8E2C-(E-Mail Removed)...
> 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 ?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Structure as object property JSheble Microsoft C# .NET 6 14th Dec 2005 08:03 PM
Using a structure as a property in a class gives error when accessing properties of structure D Witherspoon Microsoft VB .NET 6 5th Mar 2005 07:43 AM
Using a structure as a property in a class gives error when accessing properties of structure D Witherspoon Microsoft Dot NET 6 5th Mar 2005 07:43 AM
Using a structure as a property in a class gives error when accessing properties of structure D Witherspoon Microsoft Dot NET Framework Forms 6 5th Mar 2005 07:43 AM
cannot set property value in a structure using Me Sankar Nemani Microsoft VB .NET 4 22nd Sep 2004 03:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:05 PM.