Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2008

Tip: Looking for answers? Try searching our database.

User Type Property in the designer.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patricio Vidal - 02 Apr 2008 01:07 GMT
Hello,

I have a user control that has a custom type public property.  I added de
Browsable attribute so that it appears in the designer.  When I drop that
control on another control or form the custom type property is visible but I
can not assigned to one of the container fields.  If I use a know type
(ListView for example) then the property has a pull down menu showing me
those fields in the container that matches the type, but with my custom type
the pull down menu only has "none".  How do I solve this?

Thank you for your help,
Patricio.
Linda Liu[MSFT] - 02 Apr 2008 09:07 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.