Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:07:11+00:00 2026-06-06T22:07:11+00:00

I am binding a properties Grid to a bunch of custom Objects that are

  • 0

I am binding a properties Grid to a bunch of custom Objects that are being written by other developers. These objects are constantly being changed and updated, so they include properties that just throw NotImplemented Exceptions. Sometimes they include properties like

[Obsolete(“use thingy instead to get other thing”, true)]

Instead of annoying the other developers. with things that I know will be changed later. What can I do to make sure my properties Grid doesn’t break on those specific properties?

Thanks for the help. the other Developers appreciate it 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:07:16+00:00Added an answer on June 6, 2026 at 10:07 pm

    I imagine that you are trying to bind the PropertyGrid to the objects at runtime, not in the designer. If you mean the propertygrid in the winform designer, the answer would be different, and you should look at the postFilterEvents method of ControlDesigner.

    The simplest solution would be to set the BrowsableAttribute to false for the properties that you want to hide. This means that when the other developers add the ObsoleteAttribute, they should add [Browsable(false)], too. But I understand that you’d like something more “automatic”. You could write a method that changes the browsable attributes of the properties of an object before passing it to the PropertyGrid. This can be done getting the TypeDescriptor for each property, then getting its BrowsableAttribute, and setting its value according to the fact that there is an ObsoleteAttribute, or that it throws an exception (this has to be done via reflection, since browsable is private). The code could be something like this:

        private static void FilterProperties(object objToEdit)
        {
            Type t = objToEdit.GetType();
            PropertyInfo[] props = t.GetProperties();
            // create fooObj in order to have another instance to test for NotImplemented exceptions 
            // (I do not know whether your getters could have side effects that you prefer to avoid)
            object fooObj = Activator.CreateInstance(t);
            foreach (PropertyInfo pi in props)
            {
                bool filter = false;
                object[] atts = pi.GetCustomAttributes(typeof(ObsoleteAttribute), true);
                if (atts.Length > 0)
                    filter = true;
                else
                {
                    try
                    {
                        object tmp = pi.GetValue(fooObj, null);
                    }
                    catch
                    {
                        filter = true;
                    }
                }
                PropertyDescriptor pd = TypeDescriptor.GetProperties(t)[pi.Name];
                BrowsableAttribute bAtt = (BrowsableAttribute)pd.Attributes[typeof(BrowsableAttribute)];
                FieldInfo fi = bAtt.GetType().GetField("browsable",
                                   System.Reflection.BindingFlags.NonPublic |
                                   System.Reflection.BindingFlags.Instance);
                fi.SetValue(bAtt, !filter);
            }
        }
    

    This should work, but it’s got a limit. There must be at least a BrowsableAttribute in the class you are editing (it doesn’t matter if it’s set to true or false), otherwise the PropertyGrid will always be empty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what are these? I am confused with the extra properties in Binding {Binding Path=Customers,
I have a custom component, ExportCommandButton, that has two attached properties. This component is
Have a List bound as the itemssource for a grid. MyObject has properties that
I have a datagrid that displays a list of custom objects. This list contains
I'm trying to sort a view model binding on multiple properties. The problem is
I want to be able to add a Binding to some properties of a
the WSHTTP Binding for WCF supports Reliable Session Properties. In there I noticed a
class UserClass{ #region Class properties which are binding from DB . . . #endregion
In my application I am binding several text boxes to properties. So in c#
Is there a concise way to define properties in a ViewModel for data binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.