title | description | ms.date | ms.topic | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Fill ListObject controls with data |
Use data binding to quickly add data to your document. You can also disconnect the list object so it displays the data but is no longer bound to the data source. |
02/02/2017 |
how-to |
|
|
John-Hart |
johnhart |
mijacobs |
office-development |
You can use data binding as a way to quickly add data to your document. After binding data to a list object, you can disconnect the list object so it displays the data but is no longer bound to the data source.
[!INCLUDEappliesto_xlalldocapp]
-
Create a xref:System.Data.DataTable at the class level.
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreHostControlsExcelCS/Sheet4.cs" id="Snippet20":::
-
Add sample columns and data in the
Startup
event handler of theSheet1
class (in a document-level project) orThisAddIn
class (in an application-level project).:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreHostControlsExcelCS/Sheet4.cs" id="Snippet21":::
-
Call the xref:Microsoft.Office.Tools.Excel.ListObject.SetDataBinding%2A method and pass in the column names in the order they should appear. The order of the columns in the list object can differ from the order in which they appear in the xref:System.Data.DataTable.
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreHostControlsExcelCS/Sheet4.cs" id="Snippet22":::
-
Call the xref:Microsoft.Office.Tools.Excel.ListObject.Disconnect%2A method of
List1
.:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreHostControlsExcelCS/Sheet4.cs" id="Snippet23":::
This code example assumes you have an existing xref:Microsoft.Office.Tools.Excel.ListObject named list1
on the worksheet in which this code appears.
- Extend Word documents and Excel workbooks in VSTO Add-ins at run time
- Controls on Office documents
- Add controls to Office documents at run time
- How to: Map ListObject columns to data
- Automate Excel by using extended objects
- ListObject control
- Bind data to controls in Office solutions
- How to: Populate worksheets with data from a database
- How to: Populate documents with data from services