Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PropertyGridControl.CustomRowCreated Event

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

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v24.2.dll

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

#Declaration

public event CustomRowCreatedEventHandler CustomRowCreated

#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.

PropertyGrid - OfficeView - Show track bar for numeric property

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;
    }
}

#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.

Property Grid - Office View - CustomRowCreated

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;
}
See Also