How to set a Property ReadOnly dynamically based on another property value.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srinivas2009123
    New Member
    • Feb 2009
    • 1

    How to set a Property ReadOnly dynamically based on another property value.

    Hi,

    I have a class with two Properties like HasSubMenu, and SubMenu , object of this class is bound to property grid. The class is given below.

    Code:
    class test
    {
    
        private bool m_HasSubMenu;
        private string m_SubMenu;
         
        [Browsable(true)]
        public bool HasSubMenu
        {
            get { return m_HasSubMenu; }
            set { m_HasSubMenu = value; }
        }
    
         
        [Browsable(true)]
        [ReadOnly(true)]
        public List<Menu> SubMenu
        {
            get { return m_SubMenu; }
            set { m_SubMenu = value; }
        }
    
    }
    This object of this class (initially with HasSubMenu false and an empty SubMenu string ) is bound to a property grid. Now that I have a ReadOnlyAttribu te set for SubMenu property this string is read only and user can't edit in the property grid. But what I want is if the user changes the HasSubMenu property to true I want this string to be editable (I mean somehow I want to make this ReadOnly attribute of SubMenu property false.)



    I am not able to figure out how should I do this. Any help will be highly appreciated



    Thanks and Regrads
    Last edited by Frinavale; Feb 4 '09, 07:55 PM. Reason: Moved to C# Answers from .NET and added [code] tags
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Plan B

    Instead of worrying about making your List<> read only, just focus on making the control it is attached to read-only. Its a lot easier since most controls have a property for this.

    Comment

    Working...