Hi Patricio,
Based on my understanding, you have a user control that contains a public
property of a custom type. When you drag the user control on a form, the
public custom type property is shown in the Properties window but the sub
properties of the custom type are not shown under the custom type property,
ie. the custom type property is not expandable. If I'm off base, please
feel free to let me know.
You need to apply the ExpandableObjectConverter to the custom type to make
the custom type property expandable. For example:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Person
{
private string id;
private string name;
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
}
In addition, you must expose a ShouldSerializePropertyName method that
returns a bool in the user control to enable serialization of properties of
complex types. Internally, the Windows Forms Designer looks for a method
named ShouldSerializePropertyName to ask whether the property should be
serialized. From the Windows Forms Designer's point of view, it doesn't
matter whether your ShouldSerializePropertyName is public or private, but
choosing private removes it from client visibility.
For example:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private Person p = new Person();
public Person P
{
get { return p; }
set { p = value; }
}
bool ShouldSerializeP()
{
return true;
}
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Patricio - 02 Apr 2008 19:03 GMT
Hello Linda,
Thank you for your answer.
Actually, I think what I want is simpler than that. I just want the
Property Browser to allow the user to connect the User Control property to
one of the Host fields. For known types this works by default.
I am attaching a sample solution to show what I mean. You can see that in
the Form1 design view, when the UserControl1 is selected, the Property
Browser allows the user to select the listView1 field as the value for the
ListView property, but the same does not happens for the CustomType.
I tried the TypeConverter and the "ShouldSerialize" and it did not worked.
I'm using VS2008.
Please let me know what else can I try. Thank you,
Patricio.
> Hi Patricio,
>
[quoted text clipped - 86 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Linda Liu[MSFT] - 03 Apr 2008 10:44 GMT
Hi Patricio,
Thank you for your prompt reply and sample project!
The reason why the CustomType property doesn't allow the user to select a
value in the Properties window is that the CustomType type is neither a
control nor a component.
If you derive the class CustomType from the Control or Component class, you
should see the CustomType property of the UserControl allows the user to
select a value in the Properites window.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.