PropertyGrid and the base classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Sm9obiBPbGJlcnQ=?=

    #1

    PropertyGrid and the base classes

    Is there a way to pass a class to the SelectedObject of PropertyGrid and have
    it only show the properties in the child class and not those in the base
    class's that it is derived from?

    Thanks.

    --
    John Olbert

  • =?Utf-8?B?QTFiMmMzZDRAY29tbXVuaXR5Lm5vc3BhbQ==?=

    #2
    RE: PropertyGrid and the base classes

    I don't know of any way. You can control the behaviour of individual
    properties in the grid via the Browsable and ReadOnly attributes in the
    System.Componen tModel namespace. I've always used a dedicated class as the
    SelectedObject recipient. The dedicated class would contain a reference to
    your derived class instance. It exposes properties equivalent to just those
    on your derived class that you want to expose via the property grid. You can
    then decorate the properties on the dedicated class with attributes to
    control the behaviour of the grid. A good example of this would be when you
    want a custom editor to be used for a property when its displayed in the grid.

    This pattern is similar to how Microsoft does things in the Enterprise
    Library configuration tool. Briefly, they have hierarchies of classes
    derived from System.Configur ation.Configura tionElement. Each one does not
    get exposed in a property grid directly. Instead it has an equivalent
    ConfigurationNo de-derived class exposing just the properties that are to be
    visible in the grid.

    Hope this helps.

    David Razzetti

    "John Olbert" wrote:
    Is there a way to pass a class to the SelectedObject of PropertyGrid and have
    it only show the properties in the child class and not those in the base
    class's that it is derived from?
    >
    Thanks.
    >
    --
    John Olbert
    >

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: PropertyGrid and the base classes

      John,

      I would create a wrapper type which would implement
      ICustomTypeDesc riptor. The implementation would take the object you are
      looking to display in the property grid. Then, using reflection, you would
      pass back the properties, attributes, etc, etc, etc, which should be
      displayed (a determination you would make through reflection, no doubt).


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "John Olbert" <someone@snet.n etwrote in message
      news:6DC98622-0E55-4CD1-9197-F7E66AB6666D@mi crosoft.com...
      Is there a way to pass a class to the SelectedObject of PropertyGrid and
      have
      it only show the properties in the child class and not those in the base
      class's that it is derived from?
      >
      Thanks.
      >
      --
      John Olbert
      >

      Comment

      Working...