This documentation is archived and is not being maintained.

How to: Populate Documents with Data from Objects

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005


    Visual Studio Team System

  • Microsoft Office 2003

Data access works the same way in Microsoft Visual Studio 2005 Tools for the Microsoft Office System projects as it does in Windows Forms projects. You use the same tools and code to bring the data into your solution, and you can even use Windows Forms controls to display the data. In addition, you can take advantage of controls called host controls, native objects in Microsoft Office Word that have been enhanced with events and data binding capability. For more information, see Host Items and Host Controls Overview.

To populate a document with data from an object

  1. Open your Microsoft Office Word 2003 application in Visual Studio, with the document open in the designer.

  2. Open the Data Sources window and create a data source for your project. For more information, see How to: Connect to Data in an Object.

  3. Drag the field you want from the Data Sources window to your document. By default, a Bookmark control is created on the document for each individual field. You can change this default by selecting the field in the Data Sources window and then choosing a different control from the drop-down list.

    A BindingSource is created that is bound to the object class in your project.

  4. In your code, create an instance of the object class.

  5. Assign that instance to the DataSource property of the BindingSource.

When you run the project, the controls display the first record in the data source. You can enable scrolling through the records by handling the currency events using the objects in the BindingSource.

See Also