How to: Resize ListObject Controls
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Document-level projects
Application-level projects
For more information, see Features Available by Application and Project Type. |
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.
You can resize ListObject controls at design time or at run time in document-level projects. Starting in Visual Studio 2008 Service Pack 1 (SP1), you can resize ListObject controls at run time in an application-level project.
This topic describes the following tasks:
Resizing ListObject controls at design time
Resizing ListObject controls at run time in a document-level project
Resizing ListObject controls at run time in an application-level project
For more information about ListObject controls, see ListObject Control.
For a related video demonstration, see How Do I: Add Columns to a Data-Bound List Object at RunTime?.
Resizing a ListObject Control at Design Time
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
Right-click a ListObject control.
Point to List, and then click Resize List on the shortcut menu.
Select the cells you want to use to define the size of the list.
Click OK.
Resizing a ListObject Control at Run Time in a Document-Level Project
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
Create a ListObject control that spans cell A1 through B3 on Sheet1.
Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _ Me.Controls.AddListObject(Me.Range("A1", "B3"), "List1")
Microsoft.Office.Tools.Excel.ListObject list1 = this.Controls.AddListObject(this.Range["A1", "B3"], "list1");
Resize the list to include cells A1 through C5.
List1.Resize(Range.Item("A1", "C5"))
list1.Resize(this.Range["A1", "C5"]);
Resizing a ListObject at Run Time in an Application-Level Project
Starting in SP1, 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 application-level add-in, see How to: Add ListObject Controls to Worksheets.
To resize a list object programmatically
Create a ListObject control that spans cell A1 through B3 on Sheet1.
Dim worksheet As Worksheet = CType(Application.ActiveSheet, _ Excel.Worksheet).GetVstoObject() Dim list1 As Microsoft.Office.Tools.Excel.ListObject list1 = worksheet.Controls.AddListObject _ (worksheet.Range("$A$1:$B$3"), "MyListObject")
Worksheet worksheet = ((Excel.Worksheet)this.Application.ActiveSheet). GetVstoObject(); Microsoft.Office.Tools.Excel.ListObject list1; list1 = worksheet.Controls.AddListObject (worksheet.Range["$A$1:$B$3", missing], "MyListObject");
Resize the list to include cells A1 through C5.
list1.Resize(worksheet.Range("A1", "C5"))
list1.Resize(worksheet.Range["A1", "C5"]);
See Also
Tasks
How to: Add ListObject Controls to Worksheets
How to: Resize Bookmark Controls
How to: Resize NamedRange Controls
Concepts
Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time
Excel Application-Level Add-in Development
Adding Controls to Office Documents at Run Time
Host Items and Host Controls Overview
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a section that shows how to resize a list object in an application-level add-in. |
SP1 feature change. |