Share via


ControlExtensions.AddDataGridView Method

Definition

Overloads

AddDataGridView(ControlCollection, Range, Single, Single, String)

Adds a new DataGridView control to the document in the specified size and location.

AddDataGridView(ControlCollection, Single, Single, Single, Single, String)

Adds a new DataGridView control to the document in the specified size and location.

AddDataGridView(ControlCollection, Range, Single, Single, String)

Adds a new DataGridView control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::DataGridView ^ AddDataGridView(Microsoft::Office::Tools::Word::ControlCollection ^ controls, Microsoft::Office::Interop::Word::Range ^ range, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.DataGridView AddDataGridView (this Microsoft.Office.Tools.Word.ControlCollection controls, Microsoft.Office.Interop.Word.Range range, float width, float height, string name);
static member AddDataGridView : Microsoft.Office.Tools.Word.ControlCollection * Microsoft.Office.Interop.Word.Range * single * single * string -> Microsoft.Office.Tools.Word.Controls.DataGridView
<Extension()>
Public Function AddDataGridView (controls As ControlCollection, range As Range, width As Single, height As Single, name As String) As DataGridView

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

The location of the control.

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

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

Returns

The control that was added to the document.

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.

Examples

The following code example adds a DataGridView control to the first paragraph in the document, and then adds two columns to the control. To use this example, run it from the ThisDocument class in a document-level project.

private void WordRangeAddDataGridView()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.DataGridView
        dataGridView1 = this.Controls.AddDataGridView(
        this.Paragraphs[1].Range, 190, 112.5F, "dataGridView1");
    dataGridView1.Columns.Add("firsName", "First Name");
    dataGridView1.Columns.Add("lastName", "Last Name");
}
Private Sub WordRangeAddDataGridView()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim DataGridView1 As Microsoft.Office.Tools.Word. _
        Controls.DataGridView = Me.Controls.AddDataGridView( _
        Me.Paragraphs(1).Range, 190, 112.5F, "DataGridView1")
    DataGridView1.Columns.Add("firsName", "First Name")
    DataGridView1.Columns.Add("lastName", "Last Name")
End Sub 

Remarks

This method enables you to add DataGridView objects to the end of the ControlCollection.

To remove a DataGridView that was added programmatically, use the Remove method.

Applies to

AddDataGridView(ControlCollection, Single, Single, Single, Single, String)

Adds a new DataGridView control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::DataGridView ^ AddDataGridView(Microsoft::Office::Tools::Word::ControlCollection ^ controls, float left, float top, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.DataGridView AddDataGridView (this Microsoft.Office.Tools.Word.ControlCollection controls, float left, float top, float width, float height, string name);
static member AddDataGridView : Microsoft.Office.Tools.Word.ControlCollection * single * single * single * single * string -> Microsoft.Office.Tools.Word.Controls.DataGridView
<Extension()>
Public Function AddDataGridView (controls As ControlCollection, left As Single, top As Single, width As Single, height As Single, name As String) As DataGridView

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
Single

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

top
Single

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

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

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

Returns

The control that was added to the document.

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 DataGridView control to the start of the document, and then adds two columns to the control. To use this example, run it from the ThisDocument class in a document-level project.

private void WordAddDataGridView()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.DataGridView
        dataGridView1 = this.Controls.AddDataGridView(
        0, 0, 190, 112.5F, "dataGridView1");
    dataGridView1.Columns.Add("firsName", "First Name");
    dataGridView1.Columns.Add("lastName", "Last Name");
}
Private Sub WordAddDataGridView()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim DataGridView1 As Microsoft.Office.Tools.Word. _
        Controls.DataGridView = Me.Controls.AddDataGridView( _
        0, 0, 190, 112.5F, "DataGridView1")
    DataGridView1.Columns.Add("firsName", "First Name")
    DataGridView1.Columns.Add("lastName", "Last Name")
End Sub 

Remarks

This method enables you to add DataGridView objects to the end of the ControlCollection.

To remove a DataGridView that was added programmatically, use the Remove method.

Applies to