Property Control

The property grid is ideal for showing ( and editing ) the properties of objects in Windows Forms projects.

I used it for showing and editing the resource class, you can bindt the property-grid like this:

private Properties.Settings properties = new Properties.Settings;
prpGrid.SelectedObject = properties;

The PropertyGrid is now showing your settings which you have created in the settings of your project. ( right-click you project, choose property's, choose settings).

In the form-closing event you will write the changes back to the settings: 


In the settings of you project you can use the basic-types, like int, string etc. but you can also you own types. I have created a custom type which shows a list with fields from the database, in this case a list with hiddel Colums:

    public class ColumnList : List

Because it's a list the property-grid lets allow you to add and delete items. But you will have to type them. In some case you don't want to type the entry's but let the user just choose them with a drop-down. In this case you will have to inherit your HiddenColumns class from the typeconverter class and decoratie the field wich has to become a dropdownfield with the columnlistDropDown attribute:

    public class HiddenColumns:TypeConverter 
        public string Name { get; set; }
        public bool Visible { get; set; }

Before this will work you need to create the type columnlistdropdown and override the GetStandardValues supported and the GetStandardValues method:

    public class ColumnListDropDown : TypeConverter
        private List columnnames = new CentraalArtikelenBestandData().GetColumnNamesList();

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            return true;

        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            return new StandardValuesCollection(columnnames);

In this case the standard values are populated with the columnnames list wich is a list of string with all the columnnames. Used like this the user can just choose the column wich has te be hidden from a dropdown instead of typing the columnname.

The following atributes are available for use with the property-grid

Attribute Description
CategoryAttribute  This attribute places your property in the appropriate category in a node on the property grid.
DescriptionAttribute This attribute places a description of your property at the bottom of the property grid
BrowsableAttribute This is used to determine whether or not the property is shown or hidden in the property grid
ReadOnlyAttribute Use this attribute to make your property read only inside the property grid


Specifies the default value of the property shown in the property grid


If placed above a property, this property gets the focus when the property grid is first launched. Unlike the other attributes, this attribute goes above the class.




Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!