Back to Devexpress

Classic View

windowsforms-401865-controls-and-libraries-property-grid-classic-view.md

latest5.7 KB
Original Source

Classic View

  • Oct 29, 2020
  • 3 minutes to read

|

|

The Classic View emulates the Properties window UI in Visual Studio. This view type supports the following features:

  • Expandable category rows
  • Multi-editor rows
  • Custom editors
  • Custom draw for property values

To activate the Classic View, set the PropertyGridControl.ActiveViewType property to Classic.

|

Tip

Run the following demo to see the Classic View: Property Grid module in the XtraVerticalGrid MainDemo. Office View is the default view in the demo. To switch to Classic View, right-click the Property Grid and select Use Classic view in the context menu.

Multi-Editor Rows

MultiEditorRow displays multiple properties (and their corresponding editors).

Use the Property Grid Designer to create multi-editor rows.

Use the MultiEditorRow.PropertiesCollection property to add properties to the row. You can specify the property caption, bound field name, etc.

The code below adds a multi-editor row to the Property Grid.

csharp
MultiEditorRow meRow = new MultiEditorRow();
meRow.PropertiesCollection.Add(new MultiEditorRowProperties() { FieldName = "Name", Caption = "Full Name" });
meRow.PropertiesCollection.Add(new MultiEditorRowProperties() { FieldName = "Category", Caption = "Product Category" });
meRow.PropertiesCollection.Add(new MultiEditorRowProperties() { FieldName = "Color", Caption = "Color" });
propertyGridControl1.Rows.Add(meRow);
vb
Dim meRow As New MultiEditorRow()
meRow.PropertiesCollection.Add(New MultiEditorRowProperties() With {.FieldName = "Name", .Caption = "Full Name"})
meRow.PropertiesCollection.Add(New MultiEditorRowProperties() With {.FieldName = "Category", .Caption = "Product Category"})
meRow.PropertiesCollection.Add(New MultiEditorRowProperties() With {.FieldName = "Color", .Caption = "Color"})
propertyGridControl1.Rows.Add(meRow)

Custom Draw Property Values

To custom paint a property value, complete the following steps:

The code below shows how to draw an angle.

Implement the virtual (Overridable in VB) UITypeEditor.PaintValue and UITypeEditor.GetPaintValueSupported methods to paint a property value. For more information on how to implement a custom editor, see the following help topic: UITypeEditor.

csharp
propertyGridControl1.OptionsView.AllowPaintValue = true;

public class SelectedObject {
    //The Editor attribute specifies the editor that users can utilize to edit the property value.
    [EditorAttribute(typeof(AngleEditor), typeof(System.Drawing.Design.UITypeEditor))]
    public double Angle { get; set; }
}

public class AngleEditor : System.Drawing.Design.UITypeEditor {
    // Override this method to paint the property value.
    public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e) {
        //...
    }
    // Returns whether the editor can paint the property value.
    public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context) {
        return true;
    }

    //...
}
vb
PropertyGridControl1.OptionsView.AllowPaintValue = True

Public Class SelectedObject

    Private int_angle As Double

    'The Editor attribute specifies the editor that users can utilize to edit the property value.
    <EditorAttribute(GetType(AngleEditor), GetType(System.Drawing.Design.UITypeEditor))>
    Public Property Angle() As Double
        Get
            Return int_angle
        End Get
        Set(ByVal value As Double)
            int_angle = value
        End Set
    End Property
End Class

Public Class AngleEditor
    Inherits System.Drawing.Design.UITypeEditor
    ' Override this method to paint the property value.
    Public Overrides Sub PaintValue(ByVal e As System.Drawing.Design.PaintValueEventArgs)
        '...
    End Sub

    ' Returns whether the editor can paint the property value.
    Public Overrides Function GetPaintValueSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) A
        Return True
    End Function

    '...
End Class