I have around 30 elements/objects for which i need PropertyGrid to show their properties in it,but the problem is that every object has different properties so i created a database for it. I don't know how to add p开发者_Python百科roperties in PropertyGrid from the Database.
I am going to assume that you are using Windows Forms, since you are asking about PropertyGrid
. If you have objects (meaning classes) that have the properties you want to display in your PropertyGrid
, you need only to set PropertyGrid.SelectedObject with the object you want to display. By default, PropertyGrid
will use reflection to find all the public properties of your object, and will display them.
You can use various attributes to control how PropertyGrid
displays properties. For example, you can apply the Description attribute to a class property to add help text that the property grid will display. You can use the Browsable attribute to control whether PropertyGrid
will display a given property. There are other attributes in the System.ComponentModel namespace that you can use.
精彩评论