Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do I create a PropertyGrid with dynamic Properties?

How do I create a PropertyGrid with dynamic Properties?

Scheduled Pinned Locked Moved C#
helpquestionalgorithmstutorialannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    Hi, I need to use a PropertyGrid to display various properties and allow the user to change the values. The first problem is that I've never worked with a PropertyGrid before and after searching for tutorials and experimenting on my own, I still have no clue. Almost all tutorials I found were about modified versions of the PropertyGrid that require you to already know how to use the standard version, which obviously doesn't help me. The second problem is that at runtime I don't know anything about the attibutes. I neither know the name, the type, the category, the description nor the value. Is there a way to dynamically add a collection of properties to a PropertyGrid and have it determine the necessary attributes (such as category and name) at runtime? Thanks in advance.

    G 1 Reply Last reply
    0
    • M Megidolaon

      Hi, I need to use a PropertyGrid to display various properties and allow the user to change the values. The first problem is that I've never worked with a PropertyGrid before and after searching for tutorials and experimenting on my own, I still have no clue. Almost all tutorials I found were about modified versions of the PropertyGrid that require you to already know how to use the standard version, which obviously doesn't help me. The second problem is that at runtime I don't know anything about the attibutes. I neither know the name, the type, the category, the description nor the value. Is there a way to dynamically add a collection of properties to a PropertyGrid and have it determine the necessary attributes (such as category and name) at runtime? Thanks in advance.

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      Megidolaon, Just assign:

      propertyGrid1.SelectedObject = theClassYouWantToView

      MSDN[^]

      Regards, Gareth. (FKA gareth111)

      M 1 Reply Last reply
      0
      • G Gareth H

        Megidolaon, Just assign:

        propertyGrid1.SelectedObject = theClassYouWantToView

        MSDN[^]

        Regards, Gareth. (FKA gareth111)

        M Offline
        M Offline
        Megidolaon
        wrote on last edited by
        #3

        It's not that simple. I have a class called Task which has List of TaskParameter objects. Each TaskParameter object has the properties "Name", "Type" and "Value". "Name" should be displayed as the name of a property in the grid, "Type" I want to use to validate the user input and "Value" is the value of Parameter. The amount of Parameters, their names, types, values, categories and description must be dynamiccally assignable because they change from Task to Task and the Tasks (the Tasks are also subject to change at runtime so I can't just create a different class for each Task). Is there a way to create a class that allows me to dynamically assign names, types, values, categories and description (readonly and browsable are secondary, it's assumed all properties that are in the TaskParameter collection are browsable and assignable by the user) for a property at runtime and also displays a whole collection of them at once? So far the only noteworthy results I had when using only a single TaskParameter object and when I used an array created from the TaskParameter List of the Task class, it only displays the "Name", "Type" and "Value" properties but without any descriptions, defaults or anything else.

        V 1 Reply Last reply
        0
        • M Megidolaon

          It's not that simple. I have a class called Task which has List of TaskParameter objects. Each TaskParameter object has the properties "Name", "Type" and "Value". "Name" should be displayed as the name of a property in the grid, "Type" I want to use to validate the user input and "Value" is the value of Parameter. The amount of Parameters, their names, types, values, categories and description must be dynamiccally assignable because they change from Task to Task and the Tasks (the Tasks are also subject to change at runtime so I can't just create a different class for each Task). Is there a way to create a class that allows me to dynamically assign names, types, values, categories and description (readonly and browsable are secondary, it's assumed all properties that are in the TaskParameter collection are browsable and assignable by the user) for a property at runtime and also displays a whole collection of them at once? So far the only noteworthy results I had when using only a single TaskParameter object and when I used an array created from the TaskParameter List of the Task class, it only displays the "Name", "Type" and "Value" properties but without any descriptions, defaults or anything else.

          V Offline
          V Offline
          visualhint
          wrote on last edited by
          #4

          Hi, The PropertyGrid is a complex component. If you want to use it, I recommend you to dig in the various docs, howtos, blog posts, etc. The Microsoft PropertyGrid is not very flexible but it can be powerful when you know all the internals of the ComponentModel stuff. A good starting point is the "Microsoft PropertyGrid Resource List" (see signature). If you still can't make it work, ask some detailed questions, one per particular issue (yours is a bit vague). About your last sentence, use the DescriptionAttribute and DefaultValueAttribute. If you need them to be dynamic, you will need to publish your properties with the help of a custom type descriptor and custom property descriptors. At last if a 3rd party component is an option for you, Smart PropertyGrid.Net is a time saver to build dynamic contents. Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups