Disable Property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    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
    NumberOfDecimal Places. When the user chooses Currency, I want to
    disable the NumberOfDecimal Places property so that it cannot be
    changed. How do I do this.

  • Spam Catcher

    #2
    Re: Disable Property

    Paul <pwh777@hotmail .comwrote in news:1178575492 .531969.68320
    @y5g2000hsa.goo glegroups.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
    NumberOfDecimal Places. When the user chooses Currency, I want to
    disable the NumberOfDecimal Places 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...


    Comment

    • rowe_newsgroups

      #3
      Re: Disable Property

      On May 8, 2:05 am, Spam Catcher <spamhoney...@r ogers.comwrote:
      Paul <pwh...@hotmail .comwrote in news:1178575492 .531969.68320
      @y5g2000hsa.goo glegroups.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
      NumberOfDecimal Places. When the user chooses Currency, I want to
      disable the NumberOfDecimal Places 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.Ge neral
      Public Property FormatValue() As FormatValues
      Get
      Return _FormatValue
      End Get
      Set (ByVal value as FormatValues)
      _FormatValue
      allowedToChange = (value = FormatValues.Cu rrency)
      End Get
      End Property

      Private _NumberOfDecima lPlaces As Int32 = 0
      Public ReadOnly Property NumberOfDecimal Places() As Int32
      Get
      Return _NumberOfDecima lPlaces
      End Get
      End Property

      Public Sub ChangeNumberOfD ecimalPlaces(By Val value As Int32)
      If allowedToChange Then
      _NumberOfDecima lPlaces = value
      Else
      Throw New Exception()
      End If
      End Sub

      Public Function TryChangeNumber OfDecimalPlaces (ByVal value As Int32)
      As Boolean
      If allowedToChange Then
      _NumberOfDecima lPlaces = value
      Return True
      Else
      Return False
      End If
      End Function

      Hope that helps.

      Thanks,

      Seth Rowe

      Comment

      • Paul

        #4
        Re: Disable Property

        Thanks for the replies! I'll try it out.

        Comment

        Working...