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. Visual Basic
  4. How to create Properties Dynamically in Property grid

How to create Properties Dynamically in Property grid

Scheduled Pinned Locked Moved Visual Basic
cssdatabasehelptutorial
8 Posts 4 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.
  • A Offline
    A Offline
    Anuradha612
    wrote on last edited by
    #1

    Hi, Can somebody please tell me how to manage the property grid dynamically (i.e) there are 50-100 properties in my database and not all are assigned values, i want to display only those properties which have values assigned.. can somebody suggest me some method for this. i would be a great help. Thanks in Advance Anu

    D V D 3 Replies Last reply
    0
    • A Anuradha612

      Hi, Can somebody please tell me how to manage the property grid dynamically (i.e) there are 50-100 properties in my database and not all are assigned values, i want to display only those properties which have values assigned.. can somebody suggest me some method for this. i would be a great help. Thanks in Advance Anu

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You cannot use a PropertyGrid for this. A PropertyGrid shows the public properties of an object, like an instance of a TextBox, or Label control. You're need to use something like a DataGridView control, or some other bindable grid control to show your database data.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • A Anuradha612

        Hi, Can somebody please tell me how to manage the property grid dynamically (i.e) there are 50-100 properties in my database and not all are assigned values, i want to display only those properties which have values assigned.. can somebody suggest me some method for this. i would be a great help. Thanks in Advance Anu

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

        Hi, simply write a class implementing ICustomTypeDescriptor and drop it to the SelectedObject property. This class will take care of publishing the properties it wants. With .Net 2.0 you can also use the TypeDescriptionProvider so that you don't have to modify your existing class to make it implement ICustomTypeDescriptor. You will find some resources about this subject on the PropertyGrid Resource List. If a commercial component is an option for you, you have also Smart PropertyGrid. It has a mode where you can simply call AppendProperty-like methods and fill the grid completely dynamicall without having to build separate TypeDescriptor classes. I hope this helps.

        Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

        D 1 Reply Last reply
        0
        • V visualhint

          Hi, simply write a class implementing ICustomTypeDescriptor and drop it to the SelectedObject property. This class will take care of publishing the properties it wants. With .Net 2.0 you can also use the TypeDescriptionProvider so that you don't have to modify your existing class to make it implement ICustomTypeDescriptor. You will find some resources about this subject on the PropertyGrid Resource List. If a commercial component is an option for you, you have also Smart PropertyGrid. It has a mode where you can simply call AppendProperty-like methods and fill the grid completely dynamicall without having to build separate TypeDescriptor classes. I hope this helps.

          Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          I think both of these guys are doing the same thing. My take on what they were doing was storing storing a bunch of name/value pairs in a database (they call them "properties"), then expecting the PropertyGrid to show those records. This, obviously, won't work in a straight forward manner by pointing the SelectedObject of the PG at the DataTable object. You'll get the properties of the table, not the data in it. Are you saying you would either create a custom class deriving from CustomTypeDescriptor or modifying an existing class, implementing ICustomTypeDescriptor, to wrap these name/value pairs as a PropertyDescriptorCollection?? Wouldn't you also have to extend the schema of the datatable to include, at a minimum, type information for each "property"??

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          V 1 Reply Last reply
          0
          • D Dave Kreskowiak

            I think both of these guys are doing the same thing. My take on what they were doing was storing storing a bunch of name/value pairs in a database (they call them "properties"), then expecting the PropertyGrid to show those records. This, obviously, won't work in a straight forward manner by pointing the SelectedObject of the PG at the DataTable object. You'll get the properties of the table, not the data in it. Are you saying you would either create a custom class deriving from CustomTypeDescriptor or modifying an existing class, implementing ICustomTypeDescriptor, to wrap these name/value pairs as a PropertyDescriptorCollection?? Wouldn't you also have to extend the schema of the datatable to include, at a minimum, type information for each "property"??

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

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

            Hello Dave, There is not a lot of detailed informations in the original post. So I gave a generic advice since the OP seems to ignore that the PropertyGrid can display something else than the simple sum of the public properties in a target instance. How he will get the data in his business objects and how he knows their type is beyond my knowledge of his application.

            Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

            D 1 Reply Last reply
            0
            • V visualhint

              Hello Dave, There is not a lot of detailed informations in the original post. So I gave a generic advice since the OP seems to ignore that the PropertyGrid can display something else than the simple sum of the public properties in a target instance. How he will get the data in his business objects and how he knows their type is beyond my knowledge of his application.

              Best regards, Nicolas Cadilhac @ VisualHint Smart PropertyGrid.Net Microsoft PropertyGrid Resource List Free PropertyGrid for MFC Smart FieldPackEditor.Net / DateTimePicker

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I'm just guessing at their applications too. But, any time I come up with, for example, a settings class, it usually involves a serializable class full of properties, custom types, editors, and maybe a little custom serialization code, then wrapping a UI around it, customized for that class and/or a little more generic, like using a PropertyGrid. As you probably know, adding new properties to a class like that results in "some" extra work and versioning issues. What I'm curious about is making that process more generic, where I could get away with, say, dumping a bunch of settings name/values into a database or other collection, along with the respective type information, and exposing it to a PropertyGrid through a ICustomTypeDescriptor implementation. Hmmm...

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              • A Anuradha612

                Hi, Can somebody please tell me how to manage the property grid dynamically (i.e) there are 50-100 properties in my database and not all are assigned values, i want to display only those properties which have values assigned.. can somebody suggest me some method for this. i would be a great help. Thanks in Advance Anu

                D Offline
                D Offline
                darkelv
                wrote on last edited by
                #7

                If it is for end user (versus a quick and dirty object property view for developers), property grid is not a good control for it. Probably that's why it's not included in the toolbox by default. You can add an attribute Browsable (System.ComponentModel.BrowsableAttribute)to true or false but I don't think you can change it dynamically.

                V 1 Reply Last reply
                0
                • D darkelv

                  If it is for end user (versus a quick and dirty object property view for developers), property grid is not a good control for it. Probably that's why it's not included in the toolbox by default. You can add an attribute Browsable (System.ComponentModel.BrowsableAttribute)to true or false but I don't think you can change it dynamically.

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

                  The Microsoft PropertyGrid, in the way it is available to the developer, is not really suitable for the end-user. It's not flexible enough and does not offer enough customization options. But a PropertyGrid in itself, is really suitable in so many cases... If it's done well, it can do the job better than any other control. I have written a paper some time ago showcasing a lot of examples in the industry: Why use a PropertyGrid in your application?

                  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