473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 1335
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
7
by: Raymond Lewallen | last post by:
Want to know if/how to get a list of properties that are available in a class and store the properties names in an arraylist. TIA, Raymond Lewallen
2
by: =?Utf-8?B?Z2FkeWE=?= | last post by:
I use one of 2 arrays dependent on the country. Rather than say: if exchangeID = 1 then dim myPlaceBets() as As UK.exchange.PlaceBets many statements myPlaceBetsReq.bets = myPlaceBets else...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.