Back to Devexpress

PropertyGridControl.CustomRowCreated Event

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

latest7.3 KB
Original Source

PropertyGridControl.CustomRowCreated Event

Allows you to customize PropertyGridControl rows when this PropertyGridControl has the Office View applied.

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

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

Declaration

csharp
public event CustomRowCreatedEventHandler CustomRowCreated
vb
Public Event CustomRowCreated As CustomRowCreatedEventHandler

Event Data

The CustomRowCreated event's data class is DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs.

Remarks

The CustomRowCreated event fires when the PropertyGridControl generates rows in Office View mode. This event allows you to customize created rows.

Example - Display Trackbar for Numeric Property

The following CustomRowCreated event handler adds a trackbar editor for the BorderSize numeric property. The handler typecasts the Row event parameter to the PGridNumericEditorRow class and enables the PGridNumericEditorRow.ShowTrackBar setting. The row’s PGridNumericEditorRow.MinValue and PGridNumericEditorRow.MaxValue properties specify the trackbar’s boundary values.

csharp
private void PropertyGridControl1_CustomRowCreated(object sender, DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs e) {
    if (e.Row.Properties.FieldName == "BorderSize") {
        PGridNumericEditorRow row = e.Row as PGridNumericEditorRow;
        row.MinValue = 0;
        row.MaxValue = 10;
        row.ShowTrackBar = true;
        row.IgnoreMinMaxForSpinEdit = true;
    }
}
vb
Private Sub PropertyGridControl1_CustomRowCreated(ByVal sender As Object, ByVal e As DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs)
    If e.Row.Properties.FieldName = "BorderSize" Then
        Dim row As PGridNumericEditorRow = TryCast(e.Row, PGridNumericEditorRow)
        row.MinValue = 8
        row.MaxValue = 72
        row.ShowTrackBar = True
        row.IgnoreMinMaxForSpinEdit = True
    End If
End Sub

Example - Hide Editors

The following example displays properties of an AppSettings object in a Property Grid in OfficeView mode. The code handles the PropertyGridControl.CustomRowCreated event to hide editors for the SystemSettings and ReportSettings properties.

csharp
public partial class Form1 : Form {
    public AppSettings Settings { get; set; } = new AppSettings();
    public Form1() {
        InitializeComponent();
        propertyGridControl1.ActiveViewType = DevExpress.XtraVerticalGrid.PropertyGridView.Office;
        propertyGridControl1.CustomRowCreated += PropertyGridControl1_CustomRowCreated;
        propertyGridControl1.SelectedObject = Settings;
    }
    private void PropertyGridControl1_CustomRowCreated(object sender, DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs e) {
        // Hide editors for "SystemSettings" and "ReportSettings" properties.
        if (e.Row.Properties.FieldName == "SystemSettings" || e.Row.Properties.FieldName == "ReportSettings") {
            e.Row = new PGridEmptyRow();
            e.Handled = true;
        }
    }
}

public class AppSettings {
    [Category("System")]
    [DisplayName("System Settings")]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public SystemSettings SystemSettings { get; } = new SystemSettings();

    [Category("System")]
    [DisplayName("Reporting")]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public ReportSettings ReportSettings { get; set; } = new ReportSettings();
}

public class SystemSettings {
    [DisplayName("Run in background")]
    [Category("System")]
    [DefaultValue(true)]
    public bool RunInBackground { get; set; } = true;

    [DisplayName("Process count")]
    [Category("System")]
    [DefaultValue(2)]
    public int ProcessCount { get; set; } = 2;
}

public class ReportSettings {
    [DisplayName("Zoom")]
    [DefaultValue(100)]
    public decimal ZoomFactor { get; set; } = 100;
}
vb
Partial Public Class Form1
    Public Property Settings() As New AppSettings()
    Public Sub New()
        InitializeComponent()
        PropertyGridControl1.ActiveViewType = DevExpress.XtraVerticalGrid.PropertyGridView.Office
        AddHandler PropertyGridControl1.CustomRowCreated, AddressOf PropertyGridControl1_CustomRowCreated
        PropertyGridControl1.SelectedObject = Settings

    End Sub
    Private Sub PropertyGridControl1_CustomRowCreated(ByVal sender As Object, ByVal e As DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs)
        ' Hide editors for "SystemSettings" and "ReportSettings" properties.
        If e.Row.Properties.FieldName = "SystemSettings" OrElse e.Row.Properties.FieldName = "ReportSettings" Then
            e.Row = New PGridEmptyRow()
            e.Handled = True
        End If
    End Sub

    Public Class AppSettings
        <Category("System")>
        <DisplayName("System Settings")>
        <TypeConverter(GetType(ExpandableObjectConverter))>
        Public ReadOnly Property SystemSettings() As New SystemSettings()

        <Category("System")>
        <DisplayName("Reporting")>
        <TypeConverter(GetType(ExpandableObjectConverter))>
        Public Property ReportSettings() As New ReportSettings()
    End Class

    Public Class SystemSettings
        <DisplayName("Run in background")>
        <Category("System")>
        <DefaultValue(True)>
        Public Property RunInBackground() As Boolean = True

        <DisplayName("Process count")>
        <Category("System")>
        <DefaultValue(2)>
        Public Property ProcessCount() As Integer = 2
    End Class

    Public Class ReportSettings
        <DisplayName("Zoom")>
        <DefaultValue(100)>
        Public Property ZoomFactor() As Decimal = 100
    End Class
End Class

See Also

Office View

ActiveViewType

PropertyGridControl Class

PropertyGridControl Members

DevExpress.XtraVerticalGrid Namespace