Expand Minimize
This topic has not yet been rated - Rate this topic

NamedRange.ListObject Property

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
ListObject ListObject { get; }

The following code example creates a ListObject inside of a NamedRange and then uses the ListObject property of the NamedRange to display the number of rows in the ListObject.

This example is for a document-level customization.


private void GetListObject()
{
    this.Range["B2", missing].Value2 = "Row 1";
    this.Range["C2", missing].Value2 = "Row 2";
    this.Range["D2", missing].Value2 = "Row 3";

    this.Range["B3", "B5"].Value2 = 10;
    this.Range["C3", "C5"].Value2 = 20;
    this.Range["D3", "C5"].Value2 = 30;

    Microsoft.Office.Tools.Excel.ListObject listObject1 =
        this.Controls.AddListObject(
        this.Range["B2", "D5"], "listObject1");

    Microsoft.Office.Tools.Excel.NamedRange getListObjectRange = 
        this.Controls.AddNamedRange(
        this.Range["A1", "E6"], "getListObjectRange");
    getListObjectRange.Select();

    int numberOfRows = 
        getListObjectRange.ListObject.DataBodyRange.Rows.Count;
    MessageBox.Show("The DataBodyRange of the ListObject contains " +
        numberOfRows + " rows.");
}


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.