Property which is not editable and can be changed with a UITypeEditor

  • Thread starter Thread starter samialtas
  • Start date Start date
S

samialtas

Guest
Hey there.

I have a decimal property named OffSeasonLimits. And I enable/disable it with the value of GeneralSettings1.OffSeason. If the value of GeneralSettings1.OffSeason is true, OffSeasonLimits property is enabled, else it's disabled.

My question is,

When I declare OffSeasonLimits as a string, it get disabled but its text is not greyed out. Please help. Thanks.


<RefreshProperties(System.ComponentModel.RefreshProperties.All)>
<[ReadOnly](True)>
<Editor(GetType(LocationEditor), GetType(UITypeEditor))>
Public Property OffSeasonLimits As Decimal



Public Sub EnableDisableProperty(PropertyName As String, CurrentStatus As Boolean)
Dim aa As Boolean = CurrentStatus
Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(GeneralSettings1.[GetType]())(PropertyName)
Dim attribute As ReadOnlyAttribute = CType(descriptor.Attributes(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
Dim fieldToChange As FieldInfo = attribute.[GetType]().GetField("isReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
fieldToChange.SetValue(attribute, aa <> True)
End Sub



Private Sub PropertyGrid1_PropertyValueChanged(s As Object, e As PropertyValueChangedEventArgs) Handles PropertyGrid1.PropertyValueChanged
EnableDisableProperty("OffSeasonLimits", GeneralSettings1.OffSeason)
End Sub

Continue reading...
 
Back
Top