Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
Display a Windows Form from Excel 2003 #85
Chapter 11, Visual Studio Tools for Office
|
377
HACK
you created for this class. This should be done after the call to Initialize-
Component
(which initializes the form):
public GetCustomer (OfficeCodeBehind targetExcelCode)
{
InitializeComponent( );
this.excelCode = targetExcelCode;
}
The next step is to create an instance of the Windows Forms class and call
the
Show method. In this example, you are going to do this when the work-
book first opens the new document:
protected void ThisWorkbook_Open( )
{
GetCustomer inputForm = new GetCustomer (this);
inputForm.Show( );
}
At this point, you should be able to build and test your code. Excel should
start and open your blank form. Sure, it doesn’t do much yet, but you
should run it now to make sure that all of the pieces are falling together.
Gather Data with the Windows Forms
Now that you have the form opening up when the user starts a new instance
of the Excel document, you need to add code to the form’s Load event to
populate the combo boxes with data from a database. First, to make life a
little easier, in your Windows Forms class, you need to add references to the
data namespaces listed here:
using System.Data;
using System.Data.SqlClient;
Next, create a method to handle the form’s Load event. The easiest way to
do this is to double-click anywhere on the form (as long as it is not a con-
trol), and you’ll be placed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page