all groups > dotnet windows forms designtime > april 2008 >
You're in the

dotnet windows forms designtime

group:

User Type Property in the designer.


User Type Property in the designer. Patricio Vidal
4/1/2008 8:07:42 PM
dotnet windows forms designtime:
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.
RE: User Type Property in the designer. v-lliu@online.microsoft.com
4/2/2008 8:07:34 AM
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.

Re: User Type Property in the designer. Patricio
4/2/2008 2:03:30 PM
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.

[quoted text, click to view]


begin 666 CustomTypeProperty.zip
M4$L#! H``````*)I@C@````````````````7````0W5S=&]M5'EP95!R;W!E
M<G1Y+V)I;B]02P,$"@``````Q&F". ```````````````!T```!#=7-T;VU4
M>7!E4')O<&5R='DO8FEN+T1E8G5G+U!+`P04````" "':H(X4^30.,D```"+
M`0``( ```$-U<W1O;51Y<&50<F]P97)T>2]#=7-T;VU4>7!E+F-SC5"]"L(P
M$-X+?8>,=>D+.$D5%T7!;N*0QK-$TKN8I&H1G\S!1_(53*R44A<A'/?]72YY
M/9ZUE5BR36,=5.,XZL,T(Z5 .$EHTSD@&"F&EH7$TY#+X>J&W-3PBX>_-U2:
M$- M:0_*JW&$O *KN0"6U=91E3<:UH8T&-?$T2V.&-L&+B,\>PY,XCRB0S*[
M:HY[7BA8%4>_=F<8C78AI>M"2<&$XM;V9@?I,[5S2'1LTC)?@;$2PI/:WG;]
M/2S<2_H/(]/6?_.?XL\;4$L#!!0````(`-=I@C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N*2/F =-9+%(1*)!^6>X953C30P<U;.
M]^K%N%Z;/2Q^[,TK(ZOYX$ZK_M8$34 =([/*RRB?%+?;L'#*EE\6^-+"#H-V
M\M4M(\# (\3W)L,Y8UV;^UVE-_6$EW:&=;'C@*N1?&L'Y 6/15UKD$X@BB :
M@A*YG*X=1X)Z_,IS5 "UH*R#^M3_[K@JQ[),]33,<T!G5 L9H,@',[Q[(H(E
MU?=6`DN=2ZHTDA>M.5B9KB34]^I"_\$YG\O:QA@JIPQS+3"88%P,'_NU)5=U
MK!I6WCO!-X>&G4UC!U"N*O_9"+Z5&N%/`B8-7Y*"I8^=&? ]$V@32#?9_%I$
MUS#8>@T6SL8LA=$=Q=9^P4WLX_(MMXG7M!/<*)#X.M!2)%MZ647BRUM:S7R3
MSO8DGB9EMM[C4_.&(>5NTG5>O'P[*K;$8ILTCZ97MV^7BV'/P):Y>K%/+@?'
M#ZT6;I\DQ=TTGI,YECXI5D:"SR6\!.HUH5&TH&NJ/A*&0SH"8NI=Q$3?`2DM
MD@GNG ^$\HCDN.JF9D@2IEUB$2!7*"V)PI=?0B4!._!))A@^V9# E'Y-% "I
M1(V&!+=1NT7(BX%/S!*#:S'@&Q46RW$)TX(?K,N&L0:Y3;35PC_+32_X%U!+
M`P04````" !D:8(XQX7\*V$!``"=`P``*0```$-U<W1O;51Y<&50<F]P97)T
M>2]#=7-T;VU4>7!E4')O<&5R='DN<VQNI9*Q3L,P$(;G1LH[6&$!J8YL&F@S
M,#A.# .@B@![VCB5D1M'<8)4E3X9`X_$*^"(MC1MA%#9?+__N_ON[,_W#]NZ
M$]-2:955X%GH.I$@KNI4*! K65="Y8 )R?N J7*>& \O=2-BY")D6R=[2><(
MC6QK7*H7/JU.G24C$?(BBN `808Q#@<P8%X`$:+(8T,_8@%=.6?@"CBTUI6:
Re: User Type Property in the designer. v-lliu@online.microsoft.com
4/3/2008 9:44:36 AM
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.

AddThis Social Bookmark Button