By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,870 Members | 2,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,870 IT Pros & Developers. It's quick & easy.

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

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. class test
  2. {
  3.  
  4.     private bool m_HasSubMenu;
  5.     private string m_SubMenu;
  6.  
  7.     [Browsable(true)]
  8.     public bool HasSubMenu
  9.     {
  10.         get { return m_HasSubMenu; }
  11.         set { m_HasSubMenu = value; }
  12.     }
  13.  
  14.  
  15.     [Browsable(true)]
  16.     [ReadOnly(true)]
  17.     public List<Menu> SubMenu
  18.     {
  19.         get { return m_SubMenu; }
  20.         set { m_SubMenu = value; }
  21.     }
  22.  
  23. }
  24.  
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 ReadOnlyAttribute 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
Feb 4 '09 #1
Share this Question
Share on Google+
1 Reply


tlhintoq
Expert 2.5K+
P: 3,525
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.
Feb 5 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.