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

  • Question

  • 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.

        <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

    • Edited by samialtas Friday, June 14, 2019 9:33 AM
    Friday, June 14, 2019 9:32 AM

All replies

  • Hello,

    Take a look at the following code sample, specifically 

    <Browsable(True)> _ 
    <EditorBrowsable(EditorBrowsableState.Always)> _ 
    <System.ComponentModel.Description("Current connection string for file")> _ 
    Public ReadOnly Property TheConnectionString As String 
              Return Me.ConnectionString 
    	End Get 
    End Property 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, June 14, 2019 10:28 AM