473,508 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable Property

I have two properties in a user control of mine. One is FormatValue
which the user can select Currency, Number, etc. The second is
NumberOfDecimalPlaces. When the user chooses Currency, I want to
disable the NumberOfDecimalPlaces property so that it cannot be
changed. How do I do this.

May 7 '07 #1
3 1581
Paul <pw****@hotmail.comwrote in news:1178575492.531969.68320
@y5g2000hsa.googlegroups.com:
I have two properties in a user control of mine. One is FormatValue
which the user can select Currency, Number, etc. The second is
NumberOfDecimalPlaces. When the user chooses Currency, I want to
disable the NumberOfDecimalPlaces property so that it cannot be
changed. How do I do this.
You can't "hide" the property ... but you can throw an exception if the
user attempts to access the property if the first value is set.

Otherwise just ignore the second property in your logic.

Or make both properties read only... and provide a method to set the
values...
May 8 '07 #2
On May 8, 2:05 am, Spam Catcher <spamhoney...@rogers.comwrote:
Paul <pwh...@hotmail.comwrote in news:1178575492.531969.68320
@y5g2000hsa.googlegroups.com:
I have two properties in a user control of mine. One is FormatValue
which the user can select Currency, Number, etc. The second is
NumberOfDecimalPlaces. When the user chooses Currency, I want to
disable the NumberOfDecimalPlaces property so that it cannot be
changed. How do I do this.

You can't "hide" the property ... but you can throw an exception if the
user attempts to access the property if the first value is set.

Otherwise just ignore the second property in your logic.

Or make both properties read only... and provide a method to set the
values...
You can't "hide" the property ... but you can throw an exception if the
user attempts to access the property if the first value is set.
Or make both properties read only... and provide a method to set the
values..
I usually go with a readonly property and add a Change method and a
boolean TryChange function for setting the property's value. The
TryChange return a boolean indicating whether the attempt was
successful. And since it uses an internal indicator of whether the
property can be changed it prevents the performance hit of throwing
and catching an exception (though in this case it would be
negligible). Here's an example for the OP:

' Typed in Message

Private allowedToChange As Boolean = False

Private _FormatValue As FormatValues = FormatValues.General
Public Property FormatValue() As FormatValues
Get
Return _FormatValue
End Get
Set (ByVal value as FormatValues)
_FormatValue
allowedToChange = (value = FormatValues.Currency)
End Get
End Property

Private _NumberOfDecimalPlaces As Int32 = 0
Public ReadOnly Property NumberOfDecimalPlaces() As Int32
Get
Return _NumberOfDecimalPlaces
End Get
End Property

Public Sub ChangeNumberOfDecimalPlaces(ByVal value As Int32)
If allowedToChange Then
_NumberOfDecimalPlaces = value
Else
Throw New Exception()
End If
End Sub

Public Function TryChangeNumberOfDecimalPlaces(ByVal value As Int32)
As Boolean
If allowedToChange Then
_NumberOfDecimalPlaces = value
Return True
Else
Return False
End If
End Function

Hope that helps.

Thanks,

Seth Rowe

May 8 '07 #3
Thanks for the replies! I'll try it out.

May 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5965
by: Bob Bedford | last post by:
I create checkboxes using datas from a database (with PHP). I store all values in an array, as I must pass this value like a Form value. Now, in some cases, when a checkbox is selected, I must...
1
1969
by: Lars Netzel | last post by:
Hello, Making your own WebCustomControl, how you do disable properties in the design view? For example my WebCustomControl does not use text, so the default property Font is missleading when...
13
14557
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the...
6
1513
by: | last post by:
hi, how to disable the controls in page? thanks For each myControl in Page.Controls 'want to disable myControl? Next
3
11609
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7036
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...
0
7489
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...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
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...
0
1547
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 ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.