468,735 Members | 2,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,735 developers. It's quick & easy.

Property and type

Hi

Can one property have different types?
For example, i need to property type to be dependend on second property.

Pirvate MyValue as Object
Private MyType as Integer

Public Property PType() as Integer
Get
Return MyType
End Get
Set (ByVal value As Integer)
MyType=value
If MyType=1 Then Value=Windows.Forms.CheckState
If MyType=2 Then Value=Boolean
End Set
End Property

Public Property Value() as Object
Get
Return MyValue
End Get
Set (ByVal value as Object)
MyValue=value
End Set
End Property

But on propertywindow property "Value" is "grayed" and i cant choose
values.
Regards;
Meelis
Mar 20 '06 #1
3 1191
Meelis wrote:
Hi

Can one property have different types?
For example, i need to property type to be dependend on second property.

Pirvate MyValue as Object
Private MyType as Integer

Public Property PType() as Integer
Get
Return MyType
End Get
Set (ByVal value As Integer)
MyType=value
If MyType=1 Then Value=Windows.Forms.CheckState
If MyType=2 Then Value=Boolean
End Set
End Property

Public Property Value() as Object
Get
Return MyValue
End Get
Set (ByVal value as Object)
MyValue=value
End Set
End Property

But on propertywindow property "Value" is "grayed" and i cant choose
values.
Regards;
Meelis


You can not have a property be the same name as the variable.

Try:
Public Property Value() as Object
Get
Return MyValue
End Get
Set (ByVal InValue as Object)
MyValue=InValue
End Set
End Property

But you can not assign "MyValue" a type like you are trying. What are
you trying to accomplish?
Mar 20 '06 #2
Hi Chris

Yes, in .NET you can have same names for property and value, but thats not
the probelm.
I'll try to explain what i want in my poor english
Lets say i have two properties p1 and p2

p1 is integer and value can be 1 or 2
if value is 1 then p2 type must be Windows.Forms.CheckState
and if value is2 then p2 type must me Boolean

now step by step

If user selects in property window p1 value to 1,
p2 type mus change to CheckState and user can select Checked, UnChecked aso.

If p1 value is selected to be 2
p2 type must be Boolean and use can select True or False.

Hope you understand me :)
Meelis



"Chris" <no@spam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Meelis wrote:
Hi

Can one property have different types?
For example, i need to property type to be dependend on second property.

Pirvate MyValue as Object
Private MyType as Integer

Public Property PType() as Integer
Get
Return MyType
End Get
Set (ByVal value As Integer)
MyType=value
If MyType=1 Then Value=Windows.Forms.CheckState
If MyType=2 Then Value=Boolean
End Set
End Property

Public Property Value() as Object
Get
Return MyValue
End Get
Set (ByVal value as Object)
MyValue=value
End Set
End Property

But on propertywindow property "Value" is "grayed" and i cant choose
values.
Regards;
Meelis


You can not have a property be the same name as the variable.

Try:
Public Property Value() as Object
Get
Return MyValue
End Get
Set (ByVal InValue as Object)
MyValue=InValue
End Set
End Property

But you can not assign "MyValue" a type like you are trying. What are
you trying to accomplish?

Mar 20 '06 #3
Hi Meelis,

A property can have only one type, but if you declare it as Object, it can
hold values of different types (Windows.Forms.CheckState or Boolean, as in
your case). However, a class with an Object type property in a PropertyGrid
(used by the properties window) won´t show the enum values for the type,
since the type is Object and the PropertyGrid looks at the property type,
not at the type of the actual value (which could be Nothing). So, for the
PropertyGrid to work as you expect, you need two properties, one Boolean and
other Windows.Forms.CheckState and the design-time architecture is powerful
enough (at least .NET 2.0) to dinamically allow hiding one or the other
property to the PropertyGrid depending on the value of a 3rd property. You
can do this adding or removing the Browsable attribute to the property of
component instance, not to the property of the type (it could affect other
instances).

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Meelis" <me*@hot.ee> escribió en el mensaje
news:Ob**************@TK2MSFTNGP14.phx.gbl...
Hi Chris

Yes, in .NET you can have same names for property and value, but thats not
the probelm.
I'll try to explain what i want in my poor english
Lets say i have two properties p1 and p2

p1 is integer and value can be 1 or 2
if value is 1 then p2 type must be Windows.Forms.CheckState
and if value is2 then p2 type must me Boolean

now step by step

If user selects in property window p1 value to 1,
p2 type mus change to CheckState and user can select Checked, UnChecked
aso.

If p1 value is selected to be 2
p2 type must be Boolean and use can select True or False.

Hope you understand me :)
Meelis

Mar 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.