HOW TO: Handle Events for the Office Web Components in Visual Studio .NET (328275)
The information in this article applies to:
- Microsoft Office XP Web Components
- Microsoft Visual C# .NET (2002)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
This article was previously published under Q328275 SUMMARY The default class wrappers that are generated by Microsoft
Visual Studio .NET do not allow you to handle events for the Office XP Chart,
Spreadsheet, and PivotTable Web components. To handle the events for these
components, you can modify the source code for these class wrappers, and then
recompile. This article describes how to modify and how to regenerate the class
wrappers for the Office XP Web Components so that you can manage their events
in a Visual Studio .NET application.
back to the top
Background Microsoft Visual Studio .NET generates an event listener class
that implements an event interface. This event listener class is passed to the
Office Web Components (OWC). The OWC then calls the QueryInterface for the
IDispatch interface, instead of the event interface. However, the IDispatch
interface for the generated class does not contain the dispatch identifiers
(DISPIDs) for the events. To resolve this issue, you can mark the generated
class with the ClassInterfaceType.None value to force COM Interop to return IDispatch for the interface
instead of for the class. The IDispatch interface does contain the event
DISPIDs.
back to the top
Steps to Modify and to Rebuild Class WrappersNOTE: The steps in this article assume that you have installed the
Microsoft Office XP Primary Interop Assemblies (PIAs).
For additional information about the Office XP PIAs, click
the article number below to view the article in the Microsoft Knowledge Base: 328912 INFO: Office XP PIAs Available for Download
- Start the Visual Studio .NET command prompt.
- Create a new directory, and then change to that directory:
md c:\owc10
cd "c:\owc10"
- Generate the source code for C# for the Windows forms
wrapper:
aximp "c:\program files\common files\microsoft shared\web components\10\owc10.dll" /source
- Delete the generated assembly AxOWC10.dll:
del c:\owc10\axowc10.dll
- Open C:\OWC10\AxOWC10.cs in any text editor.
- Add [ToolboxItem(true)] to the generated class for the Chart, the Spreadsheet, and the
PivotTable components. For example:
[System.ComponentModel.ToolboxItem(true)]
public class AxChartSpace : System.Windows.Forms.AxHost {
...
}
-and-
[System.ComponentModel.ToolboxItem(true)]
public class AxSpreadsheet : System.Windows.Forms.AxHost {
...
}
-and-
[System.ComponentModel.ToolboxItem(true)]
public class AxPivotTable : System.Windows.Forms.AxHost {
...
}
- Mark the event classes as ClassInterfaceType.None:
[System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxChartSpaceEventMulticaster : OWC10.IChartEvents {
...
}
-and-
[System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxSpreadsheetEventMulticaster : OWC10.ISpreadsheetEventSink {
...
}
-and-
[System.Runtime.InteropServices.ClassInterface(
System.Runtime.InteropServices.ClassInterfaceType.None)]
public class AxPivotTableEventMulticaster : OWC10.IPivotControlEvents {
...
}
- Save your changes to AxOWC10.cs, and then return to the
command prompt.
- Add "C:\Program Files\Microsoft.NET\Primary Interop
Assemblies" to your LIB environment variable:
set lib=c:\program files\microsoft.net\primary interop assemblies;%path%
- Copy Microsoft.Office.Interop.OWC.dll and MSComCtl.dll from
the directory where you have installed the Microsoft Office XP Primary Interop
Assemblies:
copy c:\officexppias\microsoft.office.interop.owc.dll
copy c:\officexppias\mscomctl.dll
- Compile the source file, AxOWC10.cs:
csc /t:library /r:microsoft.office.interop.owc.dll /r:adodb.dll /r:msdatasrc.dll /r:mscomctl.dll axowc10.cs
NOTE: You receive warning CS0108, "The keyword new is
required".
You may ignore this error. - Start Visual Studio .NET.
- Add your newly-compiled AxOWC10.dll to the toolbox:
- On the Tools menu, click Customize Toolbox.
- On the .NET Framework Components tab, click Browse.
- Type c:\owc10\axowc10.dll, and
then click Open.
- Click OK to dismiss the Customize Toolbox dialog box.
back to the top
REFERENCESFor additional information about
managing events for the Office Web Components by using Visual Studio .NET,
click the article numbers below to view the articles in the Microsoft Knowledge
Base: 319342 HOW TO: Handle Events for the Office XP Spreadsheet Component on a Windows Form in Visual Basic .NET
319341 HOW TO: Handle Events for the Office XP Spreadsheet Component on a Windows Form in Visual C# .NET
319557 HOW TO: Handle Events for the Office XP Chart Component by Using Visual Basic .NET
319559 HOW TO: Handle Events for the Office XP Chart Component on a Windows Form in Visual C# .NET
back to the top
Modification Type: | Major | Last Reviewed: | 7/30/2003 |
---|
Keywords: | kbHOWTOmaster kbOfficeWebChart kbOfficeWebPivot kbOfficeWebSpread KB328275 kbAudDeveloper |
---|
|