Home All Groups Group Topic Archive Search About
Author
20 Mar 2006 7:28 PM
Meelis
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

Author
20 Mar 2006 7:38 PM
Chris
Meelis wrote:
Show quoteHide quote
> 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?
Author
20 Mar 2006 7:48 PM
Meelis
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









Show quoteHide quote
"Chris" <no@spam.com> wrote in message
news:%23GHVoXFTGHA.4384@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?
Author
21 Mar 2006 10:46 AM
Carlos J. Quintero [VB MVP]
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


Show quoteHide quote
"Meelis" <m**@hot.ee> escribió en el mensaje
news:Ob1T4cFTGHA.5908@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