13.07.2015 Views

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

350CHAPTER 9 ■ SHAREPOINT AND MICROSOFT OFFICEUserControl, you can add any user <strong>in</strong>terface elements you want from the toolbox. As an example,I created a simple UserControl with a ListBox and a Button. Us<strong>in</strong>g these controls, I willload a list of product names and numbers from a database and then use the button to <strong>in</strong>sertthem <strong>in</strong>to a Word document. Figure 9-9 shows my UserControl <strong>in</strong> Visual Studio.Figure 9-9. A UserControl for a custom task paneInside of the UserControl, you can add any code you want. In my example, I simply fillthe list with product names and numbers from the AdventureWorks database when theUserControl is loaded. When the Insert button is clicked, I <strong>in</strong>sert the selected product <strong>in</strong>tothe current Word document. List<strong>in</strong>g 9-11 shows the complete code for the UserControl.List<strong>in</strong>g 9-11. Code for the Custom UserControlImports SystemImports System.DataImports System.Data.SqlClientPublic Class NamePanePrivate Sub Pane_Load( _ByVal sender As System.Object, ByVal e As System.EventArgs) _Handles MyBase.LoadTryDim connStr<strong>in</strong>g As Str<strong>in</strong>g = _"Data Source=w<strong>in</strong>2k3template;➥Initial Catalog=Adventureworks;Integrated Security=SSPI;"Dim sqlStr<strong>in</strong>g As Str<strong>in</strong>g = _"Select Name + ', ' + " _ProductNumber as FullProduct FROM Production.Product➥ORDER BY Name"Us<strong>in</strong>g objConnection As New SqlConnection(connStr<strong>in</strong>g)objConnection.Open()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!