locked
Events within an options page RRS feed

  • Question

  • Hello,

    I am trying to implement a situation with the VS tools options property grid where when a value is changed to FALSE it will disable all other properties on the form.

    Is there any way to do this without creating my own custom page?
    Tuesday, February 2, 2010 3:15 AM

Answers

  • Hello,

    Thanks for your post.
    I've taken a look at the source code of default DialogPage class, it's using System.Windows.Forms.PropertyGrid for the property page:
    Then I tried to get this PropertyGrid object in my Option Page class to see if it has some specific way to disable its properties:

    PropertyGrid grid = this.Window as PropertyGrid;

    But I can't find a way to disable its properties, the property rows are represented by System.Windows.Forms.GridItem, and the GridItem class doesn't support enabling/disabling.  After a little search, I found that's impossible to support enabling/disabling in the default PropertyGrid, a workaround is to create our custom PropertyGrid and PropertyDescriptor, when a value is changed to FALSE, change the type descriptor to indicate a specific property is 'Read-Only'.
    For more information, you could take a look at this thread: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a03f5439-4e70-42e8-9dba-db13f251c418

    Another solution is creating your own custom page as you know, the second part of this article has introduced how to do it:
    Walkthrough: Creating an Options Page

    Hope that helps.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Monday, February 15, 2010 4:17 AM
    Tuesday, February 2, 2010 8:54 AM

All replies

  • Hello,

    Thanks for your post.
    I've taken a look at the source code of default DialogPage class, it's using System.Windows.Forms.PropertyGrid for the property page:
    Then I tried to get this PropertyGrid object in my Option Page class to see if it has some specific way to disable its properties:

    PropertyGrid grid = this.Window as PropertyGrid;

    But I can't find a way to disable its properties, the property rows are represented by System.Windows.Forms.GridItem, and the GridItem class doesn't support enabling/disabling.  After a little search, I found that's impossible to support enabling/disabling in the default PropertyGrid, a workaround is to create our custom PropertyGrid and PropertyDescriptor, when a value is changed to FALSE, change the type descriptor to indicate a specific property is 'Read-Only'.
    For more information, you could take a look at this thread: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a03f5439-4e70-42e8-9dba-db13f251c418

    Another solution is creating your own custom page as you know, the second part of this article has introduced how to do it:
    Walkthrough: Creating an Options Page

    Hope that helps.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Monday, February 15, 2010 4:17 AM
    Tuesday, February 2, 2010 8:54 AM
  • How are you? Is your problem resolved? May I know whether the above suggestions helped you?

    Thanks,
    Wesley


    Wesley Yao [MSFT]
    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact: msdnmg @ microsoft.com
    Please mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, February 9, 2010 3:44 AM