How to: Resize ListObject Controls

 

You set the size of a ListObject control when you add it to a Microsoft Office Excel workbook; however, you might want to resize it at a later time. For example, you might want to change a two-column list to three columns.

Applies to: The information in this topic applies to document-level projects and VSTO add-in projects for Excel. For more information, see Features Available by Office Application and Project Type.

You can resize ListObject controls at design time or at run time in document-level projects. You can resize ListObject controls at run time in an VSTO Add-in project.

This topic describes the following tasks:

For more information about ListObject controls, see ListObject Control.

link to video For a related video demonstration, see How Do I: Add Columns to a Data-Bound List Object at RunTime?.

To resize a list, you can click and drag one of the sizing handles, or you can redefine its size in the Resize List dialog box.

To resize a list by using the Resize List dialog box

  1. Click anywhere in the ListObject table. The Table Tools, Design tab in the ribbon appears.

  2. In the Properties section, click on Resize Table.

    VSTO_ResizeTable

  3. Select the new data range for your table.

  4. Click OK.

You can resize a ListObject control at run time by using the Resize method. You cannot use this method to move the ListObject control to a new location on the worksheet. The headers must remain in the same row, and the resized ListObject control must overlap the original list object. The resized ListObject control must contain a header row, and at least one row of data.

To resize a list object programmatically

  1. Create a ListObject control that spans cell A1 through B3 on Sheet1.

                Microsoft.Office.Tools.Excel.ListObject list1 = 
                    this.Controls.AddListObject(this.Range["A1", "B3"], "list1");
    

  2. Resize the list to include cells A1 through C5.

                list1.Resize(this.Range["A1", "C5"]);
    

You can resize a ListObject control on any open worksheet at run time. For more information about how to add a ListObject control to a worksheet by using an VSTO Add-in, see How to: Add ListObject Controls to Worksheets.

To resize a list object programmatically

  1. Create a ListObject control that spans cell A1 through B3 on Sheet1.

                
                Worksheet worksheet = Globals.Factory.GetVstoObject(Application.ActiveSheet);
    
                Microsoft.Office.Tools.Excel.ListObject list1;    
                list1 = worksheet.Controls.AddListObject(worksheet.Range["$A$1:$B$3"], "MyListObject");
    

  2. Resize the list to include cells A1 through C5.

                list1.Resize(worksheet.Range["A1", "C5"]);
    

Extending Word Documents and Excel Workbooks in VSTO Add-ins at Run Time
Controls on Office Documents
Adding Controls to Office Documents at Run Time
Host Items and Host Controls Overview
Automating Excel by Using Extended Objects
ListObject Control
How to: Add ListObject Controls to Worksheets
How to: Resize Bookmark Controls
How to: Resize NamedRange Controls

Show: