Back to Devexpress

PropertyGridControl.GetPropertyDescriptor(BaseRow) Method

windowsforms-devexpress-dot-xtraverticalgrid-dot-propertygridcontrol-dot-getpropertydescriptor-x28-devexpress-dot-xtraverticalgrid-dot-rows-dot-baserow-x29.md

latest5.4 KB
Original Source

PropertyGridControl.GetPropertyDescriptor(BaseRow) Method

Returns the property descriptor for the property associated with the specified row.

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

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

Declaration

csharp
public PropertyDescriptor GetPropertyDescriptor(
    BaseRow row
)
vb
Public Function GetPropertyDescriptor(
    row As BaseRow
) As PropertyDescriptor

Parameters

NameTypeDescription
rowBaseRow

A BaseRow object which is bound to the required property.

|

Returns

TypeDescription
PropertyDescriptor

A PropertyDescriptor value.

|

Example

The following example shows how to get information on the property which corresponds to the currently selected row in a PropertyGridControl.

Assume that the form contains PropertyGridControl and Button controls. The Property Grid Control is used to browse the button’s properties. It’s required to get information on the current Property Grid Control focused property and to display it onscreen.

In the example the VGridControlBase.FocusedRowChanged event is handled to track the row focus movement in the PropertyGridControl.

The PropertyGridControl.GetPropertyDescriptor method is called to get information on the currently focused row. This includes the current property’s name and description, and the object to which the property belongs. After the information has been obtained it’s displayed within two labels, which are positioned below the PropertyGridControl. The following images illustrate the results.

The button’s Cursor property is selected:

The button’s FlatAppearance.BorderColor property is selected:

csharp
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;
using DevExpress.XtraVerticalGrid.Events;

private void propertyGridControl1_FocusedRowChanged(object sender, 
FocusedRowChangedEventArgs e) {
    PropertyGridControl pg = sender as PropertyGridControl;
    // Do not display anything when a category row is selected.
    if (e.Row is CategoryRow) {
        labelName.Text = "";
        labelDescription.Text = "";
        return;
    }
    // Will store the object which owns the current property.
    object targetObject;
    // Retrieve information on the current property.
    PropertyDescriptor propDescriptor = pg.GetPropertyDescriptor(e.Row, out targetObject);
    labelName.Text = propDescriptor.Name + ", belongs to the " + 
      targetObject.GetType().ToString() + " class";
    labelDescription.Text = propDescriptor.Description;            
}
vb
Imports System.ComponentModel
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows
Imports DevExpress.XtraVerticalGrid.Events

Private Sub PropertyGridControl1_FocusedRowChanged(ByVal sender As System.Object, _
ByVal e As FocusedRowChangedEventArgs) _ 
        Handles PropertyGridControl1.FocusedRowChanged
    Dim pg As PropertyGridControl = sender
    ' Do not display anything when a category row is selected.
    If TypeOf e.Row Is CategoryRow Then
        LabelName.Text = ""
        LabelDescription.Text = ""
        Return
    End If
    ' Will store the object which owns the current property.
    Dim targetObject As Object
    ' Retrieve information on the current property.
    Dim propDescriptor As PropertyDescriptor = pg.GetPropertyDescriptor(e.Row, targetObject)
    LabelName.Text = propDescriptor.Name + ", belongs to the " + _
      targetObject.GetType().ToString() + " class"
    LabelDescription.Text = propDescriptor.Description
End Sub

See Also

PropertyGridControl Class

PropertyGridControl Members

DevExpress.XtraVerticalGrid Namespace