Compartir a través de


ControlExtensions.AddPropertyGrid Method

Definition

Overloads

AddPropertyGrid(ControlCollection, Range, String)

Adds a new PropertyGrid control to the worksheet at the range specified.

AddPropertyGrid(ControlCollection, Double, Double, Double, Double, String)

Adds a new PropertyGrid control to the worksheet in the specified size and location.

AddPropertyGrid(ControlCollection, Range, String)

Adds a new PropertyGrid control to the worksheet at the range specified.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Excel::Controls::PropertyGrid ^ AddPropertyGrid(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, Microsoft::Office::Interop::Excel::Range ^ range, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.PropertyGrid AddPropertyGrid (this Microsoft.Office.Tools.Excel.ControlCollection controls, Microsoft.Office.Interop.Excel.Range range, string name);
static member AddPropertyGrid : Microsoft.Office.Tools.Excel.ControlCollection * Microsoft.Office.Interop.Excel.Range * string -> Microsoft.Office.Tools.Excel.Controls.PropertyGrid
<Extension()>
Public Function AddPropertyGrid (controls As ControlCollection, range As Range, name As String) As PropertyGrid

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

range
Range

A Range that provides the bounds for the control.

name
String

The name of the control that can be used to index the control in the ControlCollection instance.

Returns

Exceptions

The name or range argument is null, or the name argument has zero length.

A control with the same name is already in the ControlCollection instance.

The range that was specified is not valid. Multi-area ranges cannot be used. The range should be on the same worksheet as the ControlCollection instance.

Examples

The following code example adds a PropertyGrid control to cells A1 through C12 and a Button control to cell A14. It then displays the properties of the button in the PropertyGrid. To use this example, run it from the Sheet1 class in a document-level project.

private void ExcelRangeAddPropertyGrid()
{
    Microsoft.Office.Tools.Excel.Controls.PropertyGrid
         propertyGrid1 = this.Controls.AddPropertyGrid(
         this.Range["A1", "C12"], "propertyGrid1");

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(this.Range["A14"],
        "button1");
    button1.Text = "OK";

    propertyGrid1.SelectedObject = button1;
}
Private Sub ExcelRangeAddPropertyGrid()
    Dim PropertyGrid1 As Microsoft.Office.Tools.Excel. _
        Controls.PropertyGrid = Me.Controls. _
        AddPropertyGrid(Me.Range("A1", "C12"), _
        "PropertyGrid1")

    Dim Button1 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        Me.Range("A14"), "Button1")

    Button1.Text = "OK"
    PropertyGrid1.SelectedObject = Button1

End Sub

Remarks

The AddPropertyGrid method enables you to add PropertyGrid objects to the end of the ControlCollection. To remove a PropertyGrid control that was previously added programmatically, use the Remove method.

The control automatically resizes when the range is resized.

Applies to

AddPropertyGrid(ControlCollection, Double, Double, Double, Double, String)

Adds a new PropertyGrid control to the worksheet in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Excel::Controls::PropertyGrid ^ AddPropertyGrid(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, double left, double top, double width, double height, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.PropertyGrid AddPropertyGrid (this Microsoft.Office.Tools.Excel.ControlCollection controls, double left, double top, double width, double height, string name);
static member AddPropertyGrid : Microsoft.Office.Tools.Excel.ControlCollection * double * double * double * double * string -> Microsoft.Office.Tools.Excel.Controls.PropertyGrid
<Extension()>
Public Function AddPropertyGrid (controls As ControlCollection, left As Double, top As Double, width As Double, height As Double, name As String) As PropertyGrid

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

left
Double

The distance in points between the left edge of the control and the left edge of the worksheet.

top
Double

The distance in points between the top edge of the control and the top edge of the worksheet.

width
Double

The width of the control in points.

height
Double

The height of the control in points.

name
String

The name of the control.

Returns

The PropertyGrid control that was added to the ControlCollection instance.

Exceptions

The name argument is null or has zero length.

A control with the same name is already in the ControlCollection instance.

Examples

The following code example adds a PropertyGrid control and a Button control to the worksheet. The code then displays the properties of the button in the PropertyGrid. To use this example, run it from the Sheet1 class in a document-level project.

private void ExcelAddPropertyGrid()
{
    Microsoft.Office.Tools.Excel.Controls.PropertyGrid
         propertyGrid1 = this.Controls.AddPropertyGrid(
         0, 0, 150, 150, "propertyGrid1");

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(0, 160, 56.25, 17.25, "button1");
    button1.Text = "OK";

    propertyGrid1.SelectedObject = button1;
}
Private Sub ExcelAddPropertyGrid()
    Dim PropertyGrid1 As Microsoft.Office.Tools. _
        Excel.Controls.PropertyGrid = Me.Controls. _
        AddPropertyGrid(0, 0, 150, 150, "PropertyGrid1")

    Dim Button1 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        0, 160, 56.25, 17.25, "Button1")

    Button1.Text = "OK"
    PropertyGrid1.SelectedObject = Button1

End Sub

Remarks

The AddPropertyGrid method enables you to add PropertyGrid objects to the end of the ControlCollection. To remove a PropertyGrid control that was previously added programmatically, use the Remove method.

Applies to