473,803 Members | 3,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.F orms.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 1353
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.F orms.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.C heckState
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******** ********@tk2msf tngp13.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.F orms.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.C heckState 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******** ******@TK2MSFTN GP14.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.C heckState
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
25421
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 the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
11
12801
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
0
5569
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 is used to view the state of the running jobs and schedule new jobs. The control also runs in the context of Internet Explorer (we do this so the administrators of the jobs can always receive the latest control). The property grid is used to...
7
1699
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
1682
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 dim myPlaceBets() As AU.exchange.PlaceBets many statements
0
9566
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.