How to add properties in PropertyGrid from the database? - c#

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 properties 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.

Related

How to change the Browsable attribute of a field class after its instantiation

I’m using in my application PropertyGrid controls to display the fields of the classes. To define which fields will be displayed I’m using the Browsable attribute from ComponentModel.
I need to present the same class in two different forms, in the first all the fields must be showed and in the second, only the fields that user choose must be displayed. Is it possible to change the Browsable attribute from true to false after the class instantiation? A sample code would be very useful.

Datagridview properties form

What is the name of this form?(That is if I want to search for it, what should I search for?) and is there a way to extend it ?
The control on the right side is a PropertyGrid - so i guess it is filled by reflection. If you derive a custom type from DataColumn, this control should show all new properties as well. Here is a detailed description, which attributes you should use to decorate your properties, so that a description shows up, the right editor is shown, etc.

How to show or hide properties dynamically in the PropertyGrid?

I am using a PropertyGrid for configuring objects. I need to be able to hide or show some properties depending on the values of other properties. How this can be achieved? I know about Browsable attribute, but it only works at a compile time.
Take a look into the ICustomTypeDescriptor Interface.
Further informations on how to use it can be found in this article:
Bending the .NET PropertyGrid to Your Will.
Check this link Changing Browsable Property Attribute dynamically.A sample method is given.
Using Reflection access the Property and set its browsable property to true or false.

Is there a data-driven WPF property grid/editor available? (preferably free)

I'm looking for a data-driven WPF property grid/editor.
Most property grids appear to work using reflection to figure out the CLR properties on your class. Those properties are then displayed in the grid with editors that are specific for the type of the property.
However I don't have a specific class that I want to plug into the property grid. All I have is data, specifically a collection of name/value pairs. I want to put this collection into the grid and have a editor that is specific for the value type of each pair.
Does anyone know of an existing property grid/editor control that supports data-driven properties?
Also if it looks like the property grid/editor in Blend I won't complain ;)
I've never used it, but from what I've read about the PropertyTools for WPF on codeplex.com supports dynamically editting the current selected object.
http://propertytools.codeplex.com/

Italic text in a PropertyGrid

I'm using a PropertyGrid to show custom properties that are exposed through the implementation of ICustomTypeDescriptor.
My objects are setup in a tree structure and values for each property are either set in each object or inherited from parent objects. In the PropertyGrid I want to visually show the user what properties values are set in the selected object, and which are inherited from parent objects.
Right now I am showing every property it two categories. One set shows what the value is set to in the actual object, with a blank field if it not set. The other set shows the property values assigned to the object that are either set in the object, or inherited if not set in the object.
I would like to combine these two groups into one buy showing set properties in regular text, and inherited values in italic text. However, there doesn't seem to be any way to do that through ICustomTypeDescriptor.GetProperties(). And I don't have easy access to the properties of the PropertyGrid since they get created while the program is running.
You can't do italics - but you can do bold; the bold behaviour is determined by the PropertyDescriptor's ShouldSerializeValue; you can wrap PropertyDescriptors via various System.ComponentModel tricks (ICustomTypeDescriptor, TypeConverter or TypeDescriptionProvider) and provide your own PropertyDescriptor.
Alternatively, there are similar grids with more options, such as by VisualHint - see "Property customization" on that page.

Categories

Resources