Skip to main content
A newer version of this page is available. .

Office View

  • 3 minutes to read

PropertyGrid - Office - Thumb

The PropertyGrid control supports the Office 2016-inspired view. Its features include:

  • flat UI with no vertical and horizontal lines that separate properties in the Classic View;
  • tabbed layout;
  • numeric properties can display two editors at once (a TrackBarControl plus a default SpinEdit);

To activate this View, set the PropertyGridControl.ActiveViewType property to Office.

Organize Properties into Tabs at Design Time

In Visual Studio’s Property Grid, click the ellipsis button next to the PropertyGridControl.Tabs property. This invokes the Collection Editor dialog that allows you to create tabs and customize their captions and icons.

Property Grid - Tabs Collection Editor

After creating tabs, close the dialog and invoke the control’s smart tag. Click “Run Designer” and switch to the designer’s “Tabs” page. This page shows all available properties and draws checkboxes next to each one. Select each tab individually and check the properties you want inside them.

Property Grid - Tabs Design Time

Note that the Property Grid does not display properties that have not been assigned to an existing tab.

Organize Properties into Tabs in Code

Do the following to add tabs to the Property Grid:

  1. Handle the PropertyGridControl.TabPanelCustomize event and create new Tab objects.
  2. Modify tabs’ FieldNames collection to add rows and row categories to these tabs.
  3. Use the PropertyGridControl.SelectedTab property to choose the initially selected tab.

The code sample below organizes the “Appearance” category, the “Accessibility” category, and the “Tabs” property into two tabs. Tab headers display vector icons.


private void propertyGridControl1_TabPanelCustomize(object sender, DevExpress.XtraVerticalGrid.Events.TabPanelCustomizeEventArgs e) {
    //tab #1
    Tab tab1 = new Tab();
    //add a separate property
    tab1.FieldNames.Add("Tabs");
    //add a category
    tab1.FieldNames.Add("categoryAccessibility");
    tab1.Caption = "Main Tab";
    tab1.ImageOptions.Image = SvgBitmap.FromFile(@"D:\Work\Images\_SVG\Pages.svg").Render(null, 1);

    //tab #1
    Tab tab2 = new Tab();
    tab2.FieldNames.Add("categoryAppearance");
    tab2.Caption = "Appearance";
    tab2.ImageOptions.Image = SvgBitmap.FromFile(@"D:\Work\Images\_SVG\Medium.svg").Render(null, 1);

    e.Buttons.Add(tab1);
    e.Buttons.Add(tab2);

    propertyGridControl1.SelectedTab = propertyGridControl1.Tabs[0];
}

Display Trackbars For Numeric Properties

To display trackbars for numeric properties, handle the PropertyGridControl.CustomRowCreated event and specify minimum and maximum editor values. The following code adds a trackbar to the Font.Size property:


private void PropertyGridControl1_CustomRowCreated(object sender, DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs e) {
    if (e.Row.Properties.FieldName == "Font.Size") {
        PGridNumericEditorRow row = e.Row as PGridNumericEditorRow;
        row.MinValue = 8;
        row.MaxValue = 72;
        row.ShowTrackBar = true;
        row.IgnoreMinMaxForSpinEdit = true;
    }
}

If the selected object’s properties are retrieved at design-time, you can set all these options in the Property Grid Designer.

PropertyGrid - Office - Designer