Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
PropertyGrid Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
PropertyGrid Class

Updated: November 2007

Provides a user interface for browsing the properties of an object.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Visual Basic (Declaration)
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
<PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")> _
Public Class PropertyGrid _
    Inherits ContainerControl _
    Implements IComPropertyBrowser
Visual Basic (Usage)
Dim instance As PropertyGrid
C#
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public class PropertyGrid : ContainerControl, 
    IComPropertyBrowser
Visual C++
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
[PermissionSetAttribute(SecurityAction::LinkDemand, Name = L"FullTrust")]
public ref class PropertyGrid : public ContainerControl, 
    IComPropertyBrowser
J#
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
/** @attribute PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust") */
/** @attribute PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust") */
public class PropertyGrid extends ContainerControl implements IComPropertyBrowser
JScript
public class PropertyGrid extends ContainerControl implements IComPropertyBrowser

To use the property grid, you create a new instance of the PropertyGrid class on a parent control and set SelectedObject to the object to display the properties for.

The information displayed in the grid is a snapshot of the properties at the time the object is assigned. If a property value of the object specified by the SelectedObject is changed in code at run time, the new value is not displayed until an action is taken in the grid that causes the grid to refresh.

The property tabs within the property grid appear as buttons on the toolbar at the top of the PropertyGrid, and can vary in scope as defined in the PropertyTabScope.

The PropertyGrid control is not initially presented in the toolbox in the development environment. You can add a property grid to the toolbox, which enables you to drag a PropertyGrid onto your form. You can also define an instance of PropertyGrid by adding the appropriate code in your source code.

All public properties of the SelectedObject will be displayed in the PropertyGrid by default. You can hide a property so that it is not displayed in the PropertyGrid control by decorating it with the BrowsableAttribute and setting the value to false. You can specify the category that a property appears in by providing a category with the CategoryAttribute. You can provide descriptive text for your property that appears at the bottom of the PropertyGrid control by using the DescriptionAttribute.

The following code example illustrates creating a property grid and setting its location on a form. This example requires that you have a form with a TextBox on it.

Visual Basic
Public Sub New()

    ' The initial constructor code goes here.

    Dim propertyGrid1 As New PropertyGrid()
    propertyGrid1.CommandsVisibleIfAvailable = True
    propertyGrid1.Location = New Point(10, 20)
    propertyGrid1.Size = New System.Drawing.Size(400, 300)
    propertyGrid1.TabIndex = 1
    propertyGrid1.Text = "Property Grid"

    Me.Controls.Add(propertyGrid1)

    propertyGrid1.SelectedObject = textBox1
End Sub

C#
public Form1() {

   // The initial constructor code goes here.

   PropertyGrid propertyGrid1 = new PropertyGrid();
   propertyGrid1.CommandsVisibleIfAvailable = true;
   propertyGrid1.Location = new Point(10, 20);
   propertyGrid1.Size = new System.Drawing.Size(400, 300);
   propertyGrid1.TabIndex = 1;
   propertyGrid1.Text = "Property Grid";

   this.Controls.Add(propertyGrid1);

   propertyGrid1.SelectedObject = textBox1;
}

Visual C++
public:
   [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
   Form1()
   {
      // The initial constructor code goes here.

      PropertyGrid^ propertyGrid1 = gcnew PropertyGrid;
      propertyGrid1->CommandsVisibleIfAvailable = true;
      propertyGrid1->Location = Point( 10, 20 );
      propertyGrid1->Size = System::Drawing::Size( 400, 300 );
      propertyGrid1->TabIndex = 1;
      propertyGrid1->Text = "Property Grid";

      this->Controls->Add( propertyGrid1 );

      propertyGrid1->SelectedObject = textBox1;
   }

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker