1

I discover propertygrid which may be handy for editing or just showing some custom setup data in my program. But I have need for some attributes of properties to be changable.
Like 'readonly' attribute.

This is what I have so far:

Const myPersonCat As String = "MyPerson"
Const myDesc1 As String = "Firstname is one element"
<CategoryAttribute(myPersonCat), _
DescriptionAttribute(myDesc1), _
[ReadOnly](myBool)> _
Public Property firstname() As String
    Get
        Return _firstname
    End Get
    Set(ByVal value As String)
        If Not _firstname = value Then save_param("firstname", value, myPersonCat, myDesc1)
        _firstname = value
    End Set
End Property

Const mydesc2 As String = "but Lastname is second"
<CategoryAttribute(myPersonCat), _
DescriptionAttribute(mydesc2), _
[ReadOnly](myBool)> _
Public Property lastname() As String
    Get
        Return _lastname
    End Get
    Set(ByVal value As String)
        If Not _lastname = value Then save_param("lastname", value, myPersonCat, myDesc2)
        _lastname = value
    End Set
End Property

Save_param is call to function which saves property with basic data in database.
All of that work's nice.

But now is a question... Is here some, not too complicated way to setting 'myBool' for readonly attribute with variable instead of constant with which I can block to change some properties dependable of situation in program.
Maybe for whole category or for a single property?

Or maybe here exists some other way to get similar functionality?

Wine Too
  • 4,515
  • 22
  • 83
  • 137

1 Answers1

0

No, there is no way to change the value of the attribute. As an alternative, you can write code in your Property Set to make it throw an exception if the user tries to set the value while it is supposed to be read-only.

Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
Jack Gajanan
  • 1,596
  • 14
  • 18
  • Can you give some short example? – Wine Too Dec 20 '12 at 11:45
  • Hi Steve, here is no question on how to escape from writing readonly property but about setting property as readonly at runtime. As I understand now here is no way to do that. – Wine Too Dec 20 '12 at 13:18