[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Collapse]Property Grid
    Overview
   [Expand]Getting Started
   [Collapse]Property Definitions
     Collection Definitions
     Binding to a collection of PropertyDefinitions
     Displaying Multiple Properties in a Single Cell
    Property Attributes
    Property Categories
    Descriptions
    Expandability Customization
    Property Menu
   [Expand]Visual Elements
    Appearance Customization
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Collection Definitions

Expanded Overview

Collection definitions represent the collection properties of a bound object and specify their appearance within the property grid. Each collection definition is linked to one or multiple collection properties of a bound object. Collection definitions are represented by the CollectionDefinition objects that are stored within the PropertyGridControl.PropertyDefinitions collection.

Expanded Linking Collection Properties to Definitions

You can link a collection property of a bound object to a collection definition using an association criteria. Different criteria and combinations of criteria have different priorities. When an object property matches multiple definitions, the PropertyGrid control links it to the definition that has the highest priority.

Criteria Priority Description
Collection property path High Use the PropertyDefinitionBase.Path property to specify the direct path to the associated property.
Parent property path Medium Use the PropertyDefinition.Scope property to specify the path to the parent property.
Collection property type Low Use the PropertyDefinition.Type property to specify the type of the associated collection property.
The PropertyDefinition.TypeMatchMode property specifies the rules of type matching. See TypeMatchMode to learn more.
Note

Collection definitions generally have higher priority than property definitions when linking to collection properties, except when a property definition specifies the path to the collection property.

The following example demonstrates a declaration of a collection definition.

Expanded Displaying Collections Within the PropertyGrid Control

If the PropertyGridControl.ShowProperties property is set to WithPropertyDefinitions, you need to initialize the properties of the collection items manually. To hide the properties of collection items within a property grid, set the PropertyDefinitionBase.ShowChildren (using CollectionDefinition.ShowChildren) property to false.

The following example demonstrates a property grid that is configured in the following way.

  • The property grid displays all public properties of the bound object.
  • Only string properties are displayed within the collection items.

Expanded Collection Editing

The PropertyGrid control features the built-in collection editor. The collection editor allows end-users to make the following operations.

  • Edit collection items.
  • Add items to the collection.
  • Remove items from the collection.

The following properties control the availability of the collection editor.

Property name Property description
PropertyGridControl.UseCollectionEditor Toggles collection editing for the entire property grid.
CollectionDefinition.UseCollectionEditor Toggles collection editing for individual collections.

Expanded New Item Initializers

You can use the item initializers to create new collection items. A new item initializer is an object that implements the DevExpress.Mvvm.Native.IInstanceInitializer interface.

New item initializers allow you to do the following.

  • Specify the default property values.
  • Create objects without the default constructor.
  • Configure the new item menu. The new item menu allows end-users to add objects of different types to a collection.
The following example demonstrates a PropertyGrid control bound to a Supplier object. The Supplier.Products collection property stores objects of various types. The new item initializer allows end-users to choose the type of the object that is added to the collection.

Expanded See Also

Is this topic helpful?​​​​​​​