logo
down
shadow

Show/Hide Child Properties in PropertyGrid


Show/Hide Child Properties in PropertyGrid

By : Kent Arcelao
Date : November 18 2020, 03:42 PM
Hope that helps What you could do is reuse the DynamicTypeDescriptor class described in my answer to this question here on SO: PropertyGrid Browsable not found for entity framework created property, how to find it?
There is also another good one base ond the same utility class: Optimize class for PropertyGrid
code :


Share : facebook icon twitter icon
How to show or hide properties dynamically in the PropertyGrid?

How to show or hide properties dynamically in the PropertyGrid?


By : user3013516
Date : March 29 2020, 07:55 AM
I wish this helpful for you Take a look into the ICustomTypeDescriptor Interface.
Further informations on how to use it can be found in this article:
C# .Net 4.5 PropertyGrid: how to hide Properties

C# .Net 4.5 PropertyGrid: how to hide Properties


By : Chinmay Bhat
Date : March 29 2020, 07:55 AM
this one helps. What you could do is reuse the DynamicTypeDescriptor class described in my answer to this question here on SO: PropertyGrid Browsable not found for entity framework created property, how to find it?
like this for example:
code :
public Form1()
{
    InitializeComponent();

    DynamicTypeDescriptor dt = new DynamicTypeDescriptor(typeof(Question));

    Question q = new Question(); // initialize question the way you want    
    if (q.Element == 0)
    {
        dt.RemoveProperty("Element");
    }
    propertyGrid1.SelectedObject = dt.FromComponent(q);
}
PropertyGrid - Show properties of a specific Interface, not all properties

PropertyGrid - Show properties of a specific Interface, not all properties


By : Richardson Shane
Date : March 29 2020, 07:55 AM
help you fix your problem PropertyGrid by default shows display name of all public properties of your control which are browsable. It uses TypeDescriptor of your object to ask about its metadata including its browsable properties and their display names.
To customize this behavior you need to register a new TypeDescriptionProvider for your object.
code :
using System;
using System.ComponentModel;
using System.Windows.Forms;

public interface IMyInterface
{
    string MyProperty1 { get; set; }
    string MyProperty2 { get; set; }
}

public class MyTypeDescriptionProvider<T> : TypeDescriptionProvider
{
    public MyTypeDescriptionProvider() : base(TypeDescriptor.GetProvider(typeof(T))) { }

    public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType,
        object instance)
    {
        return base.GetTypeDescriptor(typeof(T), instance);
    }
}

[TypeDescriptionProvider(typeof(MyTypeDescriptionProvider<IMyInterface>))]
public class MyPanel : Panel, IMyInterface
{
    public string MyProperty1 { get; set; }
    public string MyProperty2 { get; set; }
}
Hide some properties in PropertyGrid at run-time

Hide some properties in PropertyGrid at run-time


By : nessguy
Date : March 29 2020, 07:55 AM
To fix the issue you can do I believe you are looking for custom type descriptors.
While the other answer is sharing correct information about Browsable attribute and BrowsableAttributes of PropertyGrid, but I'd say it's not a proper practical solution for the problem.
code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
public class CustomObjectWrapper : CustomTypeDescriptor
{
    public object WrappedObject { get; private set; }
    public List<string> BrowsableProperties { get; private set; }
    public CustomObjectWrapper(object o)
        :base(TypeDescriptor.GetProvider(o).GetTypeDescriptor(o))
    {
        WrappedObject = o;
        BrowsableProperties = new List<string>() { "Text", "BackColor" };
    }
    public override PropertyDescriptorCollection GetProperties()
    {
        return this.GetProperties(new Attribute[] { });
    }
    public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        var properties = base.GetProperties(attributes).Cast<PropertyDescriptor>()
                             .Where(p=>BrowsableProperties.Contains(p.Name))
                             .Select(p => TypeDescriptor.CreateProperty(
                                 WrappedObject.GetType(),
                                 p,
                                 p.Attributes.Cast<Attribute>().ToArray()))
                             .ToArray();
        return new PropertyDescriptorCollection(properties);
    }
}
propertyGrid1.SelectedObject = new CustomObjectWrapper(button1);
PropertyGrid: Hide base class properties, how?

PropertyGrid: Hide base class properties, how?


By : Emmanuel C
Date : March 29 2020, 07:55 AM
I hope this helps . PropertyGrid... for users Id like to leave only several of them. But now I see all, and users would be confused when see something like Dock or Cursor and such... Hope it's clear for now... , Use this attribute:
Related Posts Related Posts :
  • Estimating Amount Of time For Tasks Running in Parallel
  • Opening, Changing, and Saving Excel Sheets with DGV
  • Remapping of Database from one server to other TFS-2018
  • SQL Server: Dynamically create Column Names from JSON Auto Data
  • Is it possible to Install .net 4.7 version on my machine when .net 4.8 is already installed?
  • Getting server absolute path in .NET core 2.1
  • Regex to find last word (including symbols) on line
  • Adding element to a couchbase database with f# code
  • How to create "NuGet Package Management Project" for .NET Standard?
  • Blazor BaseURI http vs https issue
  • Does X590Certificate.Build use OCSP if ChainPolicy RevocationMode Online is used?
  • Error "NU3034 This package is signed but not by a trusted signer"
  • Blazor .net version compatibility issues
  • How to test async Task method
  • this project doesn't know how to run the profile docker
  • Azure Cloud Storage SDK UploadFromStreamAsync storing 0 bytes
  • What is the Relaese date for Microsoft Orleans which can support service fabric?
  • Make a string persistent in a .NET application
  • How do I configure Cosmos DB .NET 3.0 SDK to serialize with camel case?
  • Service segmentation fault in AWS EC2
  • How to avoid the compilation error with inconsistent accessibility of class and methods?
  • "Does not implement IControllerFactory.CreateController" in Visual Studio 2010
  • Tabs for a ASP.NET website
  • AccountManagement.UserPrincipal.Current takes 5 seconds
  • Will linq to sql work in an asp.net 2.0 web application?
  • .Net Regular Expression to get parenthetical text at end of <p> tags
  • The Project Location is Not Trusted error in Visual Studio
  • how to tell if a photo was taken in landscape or portrait? JPEG .NET metadata orientation
  • Winform and ValidateChildren()
  • Why need to mention "Supported by the .NET Compact Framework" for classes members?
  • Pass MSI parameters to .NET installer class
  • How to print stack trace of StackOverflowException
  • OnPropertyChange as an Alternative to Triggers in Entity Framework
  • "User Friendly" .net compatible Regex/Text matching tools?
  • Non-Ascii characters not supported by .net?
  • Linq SqlMethods.Like fails
  • To check whether the SQL server DB is working properly or not
  • What is the Difference between GC.GetTotalMemory(false) and GC.GetTotalMemory(true)
  • Which version of .NET is available for Xbox 360?
  • Validation (with custom ErrorTemplate) for a DataTemplate
  • is the threadpool shared - .net
  • WPF RichTextBox - Formatting of typed text
  • "ResizeEnd" equivalent for usercontrols
  • How work with common utils project
  • Using image resource in XAML markup?
  • How to use XML namespace prefixes without xmlns="..." everywhere? (.NET)
  • How to write an altered COM Structured Storage file to Disk?
  • Implementing auditing using Autofac if it support method interception?
  • How can a static class be resolved by the Unity Framework?
  • How to flush DNS cache in Windows Mobile programmatically?
  • how to set autoplay=true in google audio player?
  • Edit dialog, with bindings and OK/Cancel in WPF
  • What does MailMessage.IsBodyHtml do?
  • C# Class Library wont register for COM
  • Robust DateTime parser library for .NET
  • MySql BulkCopy/Insert from DataReader
  • How do I allow all users access to one route within a website with integrated auth?
  • Reading from a oracle temp table in a separate procedure than the one it was populted in
  • Recommendations for IPC between parent and child processes in .NET?
  • F# 1.9.9.9 and lapack
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org