You are viewing help content for pre-release software. This document and the features it describes are subject to change. Switch to the current version.

Property Grid

  • 3 minutes to read

The PropertyGridControl emulates the UI found in Visual Studio’s Properties window and in settings panels in Microsoft Office applications. You can assign any Object to the control to allow users to edit that object’s public properties.

Property Grid

Assign an Object to the Control

If you assign an object to the PropertyGridControl.SelectedObject property, the control does two things:

  • Retrieves the object’s public properties and displays their values on-screen.
  • Raises the DataSourceChanged event.

Assign Multiple Objects to the Control

You can use the PropertyGridControl.SelectedObjects property to assign an array of objects to the control. The control displays only those properties that apply to all objects in this array.

Example

The example below displays a product list in the LookUpEdit control. The Property Grid displays the selected product’s properties.

Property Grid and Lookup Editor

//Bind the lookup editor to a data source.
lookUpEdit1.Properties.DataSource = initSampleData();
lookUpEdit1.Properties.DisplayMember = "Name";
lookUpEdit1.Properties.EditValueChanged += Properties_EditValueChanged;

//Assign the selected object to the Property Grid.
private void Properties_EditValueChanged(object sender, EventArgs e) {
    propertyGridControl1.SelectedObject = (Product)lookUpEdit1.EditValue;
}

//Create a list of products.
public List<Product> initSampleData() {
    List<Product> result = new List<Product>();
    result.Add(new Product("FC GTX FE", "Fullcover GPU Blocks", 95.80f, "Nickel"));
    //. . .
    return result;
}
//Create a business object.
public class Product {
    public Product(string name, string category, float price, string color) {
        Name = name; Category = category; Price = price; Color = color;
    }
    public string Name { get; set; }
    public string Category { get; set; }
    public float Price { get; set; }
    public string Color { get; set; }
}

Views

The PropertyGridControl.ActiveViewType property specifies the Property Grid’s view:

  • Office — an Office-inspired view. See the following help topic for more information: Office View.

    Property Grid - Office View

  • Classic — a Visual Studio-inspired view. See the following help topic for more information: Classic View.

    Property Grid - Classic View

Property Description

The selected object’s properties may specify their descriptions (DescriptionAttribute). You can use the PropertyDescriptionControl to display these descriptions in your application.

Property Grid - Property Description

Use the PropertyDescriptionControl.PropertyGrid property to bind the PropertyGridControl to a PropertyDescriptionControl.

Toolbar

The control supports a toolbar as in Visual Studio’s Properties window. The toolbar displays a search box and buttons that allow users to sort and categorize grid rows.

image

You can use the Property Grid control’s smart tag menu to create the toolbar.

image

See Also