Back to Devexpress

PropertyGridControl.SelectedObject Property

windowsforms-devexpress-dot-xtraverticalgrid-dot-propertygridcontrol.md

latest10.3 KB
Original Source

PropertyGridControl.SelectedObject Property

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

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

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

Declaration

csharp
[DefaultValue(null)]
public object SelectedObject { get; set; }
vb
<DefaultValue(Nothing)>
Public Property SelectedObject As Object

Property Value

TypeDefaultDescription
Objectnull

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.

csharp
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);
vb
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraEditors.Repository
' ...
Dim pGrid As PropertyGridControl = New PropertyGridControl()
Me.Controls.Add(pGrid)
pGrid.SelectedObject = pGrid
pGrid.Dock = DockStyle.Fill
' Create a repository item which represents an in-place CheckEdit control.
Dim riCheckEdit As RepositoryItemCheckEdit = 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(GetType(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.

winforms-propertygrid-localize-property-display-names/CS/WindowsApplication3/Form1.cs#L36

csharp
propertyGridControl1.SelectedObject = null;
propertyGridControl1.Rows.Clear();

dashboard-constant-lines/CS/ConstantLineExtension.Win/ConstantLineDialog.cs#L74

csharp
void UpdatePropertyGrid() {
    propertyGridControl1.SelectedObject = listBoxControl1.SelectedItem;
    propertyGridControl1.GetRowByFieldName("MeasureId").Properties.RowEdit = measureEdit;

winforms-propertygrid-filter-object-properties/CS/Form1.cs#L15

csharp
InitializeComponent();
this.propertyGridControl1.SelectedObject = this.propertyGridControl1;
this.propertyGridControl1.GetRowByFieldName("Size").Expanded = true;

winforms-property-grid-custom-sorting/CS/Form1.cs#L19

csharp
InitializeComponent();
    this.propertyGridControl1.SelectedObject = new CustomClass() { Property1 = "one", Property2 = "two", Property3 = "three", Property4 = "four", Property5 = "five" };
}

winforms-property-grid-create-custom-editor/CS/T415077/Form1.cs#L13

csharp
Data.File file = new Data.File() { Path = "C:\\Home", Path2 = "C:\\Public" };
    this.propertyGridControl1.SelectedObject = file;
}

winforms-propertygrid-localize-property-display-names/VB/WindowsApplication3/Form1.vb#L30

vb
SetCulture(cultureName)
propertyGridControl1.SelectedObject = Nothing
propertyGridControl1.Rows.Clear()

winforms-propertygrid-filter-object-properties/VB/Form1.vb#L13

vb
InitializeComponent()
propertyGridControl1.SelectedObject = propertyGridControl1
propertyGridControl1.GetRowByFieldName("Size").Expanded = True

winforms-property-grid-custom-sorting/VB/Form1.vb#L16

vb
InitializeComponent()
    propertyGridControl1.SelectedObject = New CustomClass() With {.Property1 = "one", .Property2 = "two", .Property3 = "three", .Property4 = "four", .Property5 = "five"}
End Sub

winforms-property-grid-create-custom-editor/VB/T415077/Form1.vb#L17

vb
Dim file As Data.File = New Data.File() With {.Path = "C:\Home", .Path2 = "C:\Public"}
    propertyGridControl1.SelectedObject = file
End Sub

winforms-property-grid-unbound-rows/VB/DXApplication3/CustomDescriptor/UnboundRowHelper.vb#L22

vb
Private Sub _PropertyGrid_CustomPropertyDescriptors(ByVal sender As Object, ByVal e As CustomPropertyDescriptorsEventArgs)
    If TryCast(sender, PropertyGridControl).SelectedObject Is e.Source Then
        Dim properties As PropertyDescriptorCollection = e.Properties

See Also

BrowsableAttributes

SelectedObjects

RefreshOnSelectedObjectChanges

PropertyGridControl Class

PropertyGridControl Members

DevExpress.XtraVerticalGrid Namespace