Partager via


ListObject.ListRows Property

Gets a ListRows object that represents all the rows of data in the ListObject control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Syntax

'Declaration
ReadOnly Property ListRows As ListRows
ListRows ListRows { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.ListRows
A ListRows object that represents all the rows of data in the ListObject control.

Remarks

The ListRows object returned does not include the header, Total, or Insert rows.

To delete any items from this collection, do not use the Delete method of the item. Use the Delete method of the range of the item to delete the item; for example ListRows.Item(1).Range.Delete().

Examples

The following code example creates a ListObject, gets the collection of rows, and then displays a message showing how many rows the ListObject contains.

This example is for a document-level customization.

Private Sub ListObject_ListRows()
        Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
            Me.Controls.AddListObject(Me.Range("A1", "C4"), "List1")

        Dim List1Rows As Excel.ListRows = List1.ListRows
        MessageBox.Show("The list object contains " & _
            List1Rows.Count.ToString() & " rows.")
    End Sub
private void ListObject_ListRows()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");

    Excel.ListRows list1Rows = list1.ListRows;
    MessageBox.Show("The list object contains " +
        list1Rows.Count.ToString() + " rows.");
}

.NET Framework Security

See Also

Reference

ListObject Interface

Microsoft.Office.Tools.Excel Namespace