Skip to main content

PropertyGridControl.SelectedObject Property

Gets or sets the object whose settings are edited by the PropertyGridControl.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

[DefaultValue(null)]
public object SelectedObject { get; set; }

Property Value

Type Default Description
Object null

A Object whose settings are edited by the PropertyGridControl.

Remarks

If the Property Grid Control’s row collection is empty and an object is assigned to the SelectedObject property, the control automatically creates rows for the bound object’s properties. These rows can be accessed via the VGridControlBase.Rows property.

If the current row collection is not empty and an object is assigned to the SelectedObject property at runtime, the control will not repopulate the row collection by default. To make the control recreate rows every time an object is assigned, set the PropertyGridControl.AutoGenerateRows property to true.

If an object is assigned to the SelectedObject property at design time and the current row collection is not empty the control will ask if the row collection must be repopulated.

By default, the PropertyGridControl creates rows for the properties marked with the BrowsableAttribute.Yes attribute. To customize the collection of browsable attributes see PropertyGridControl.BrowsableAttributes.

If the selected object supports the INotifyPropertyChanged interface, the control automatically updates its content when a property changes. Set the PropertyGridControl.OptionsBehavior.RefreshOnSelectedObjectChanges property to false to prevent the automatic updates.

Example

The following code creates a PropertyGridControl and makes it display its own properties.

By default, Boolean values are edited in the Property Grid Control using a ComboBox control with the True and False options. This example shows how to associate a CheckEdit control with the Boolean data type. As a result, the CheckEdit control will be used by default for editing Boolean values.

Firstly, a repository item (RepositoryItemCheckEdit) which corresponds to the CheckEdit control is created. Then it is associated with the Boolean type via the PropertyGridControl.DefaultEditors collection.

The following image shows the result. Notice that the created repository item is customized to represent traditional check boxes as radio buttons.

CreatePropertyGrid_Ex

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraEditors.Repository;
// ...
PropertyGridControl pGrid = new PropertyGridControl();
this.Controls.Add(pGrid);
pGrid.SelectedObject = pGrid;
pGrid.Dock = DockStyle.Fill;
// Create a repository item which represents an in-place CheckEdit control.
RepositoryItemCheckEdit riCheckEdit = new RepositoryItemCheckEdit();
// Represent check boxes as radio buttons.
riCheckEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Radio;
// Associate the Boolean data type with the created repository item.
pGrid.DefaultEditors.Add(typeof(Boolean), riCheckEdit);

The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedObject property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also