Visual Studio Tools for Office: Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath

Several events are found in Visual Studio 2005 Tools for Office objects that are not found when using the Excel PIA alone. Table 4.2 lists these events. Almost all these events are events from the Excel PIA that are raised again on different objects. In the Excel PIA, for example, there is no BeforeDoubleClick event on a Range object; in fact, there are no events on the Range object at all. In VSTO, the two objects that VSTO defines that represent a Range (NamedRange and XMLMappedRange) have a BeforeDoubleClick event. VSTO adds the BeforeDoubleClick event to these objects and raises the event whenever the Worksheet.BeforeDoubleClick event is raised and passed a Range object that matches the given NamedRange or XMLMappedRange object.

Table 4.2. Events That Are Added in VSTO

Events

Raised Again From

NamedRange Object (Aggregates Range)

BeforeDoubleClick

Worksheet.BeforeDoubleClick

BeforeRightClick

Worksheet.BeforeRightClick

Change

Worksheet.Change

SelectionChange

Worksheet.SelectionChange

Selected

Worksheet.SelectionChange

Deselected

Worksheet.SelectionChange

XmlMappedRange Object (Aggregates Range)

BeforeDoubleClick

Worksheet.BeforeDoubleClick

BeforeRightClick

Worksheet.BeforeRightClick

Change

Worksheet.Change

SelectionChange

Worksheet.SelectionChange

Selected

Worksheet.SelectionChange

Deselected

Worksheet.SelectionChange

Workbook

New

Application.NewWorkbook

Startup

New event raised by VSTO

Shutdown

New event raised by VSTO

ChartSheet (Aggregates Chart)

Startup

New eventraised by VSTO

Shutdown

New event raised by VSTO

Worksheet

Startup

New event raised by VSTO

Shutdown

New event raised by VSTO

ListObject

BeforeAddDataBoundRow

New event raised by VSTO

BeforeDoubleClick

Worksheet.BeforeDoubleClick

BeforeRightClick

Worksheet.BeforeRightClick

Change

Worksheet.Change

DataBindingFailure

New event raised by VSTO

DataMemberChanged

New event raised by VSTO

DataSourceChanged

New event raised by VSTO

Deselected

Worksheet.SelectionChange

ErrorAddDataBoundRow

New event raised by VSTO

OriginalDataRestored

New event raised by VSTO

Selected

Worksheet.SelectionChange

SelectedIndexChanged

New event raised by VSTO

SelectionChange

Worksheet.SelectionChange

Another case where VSTO changes events is in the naming of the Activate event and the Select event on the Worksheet object. Both of these event names conflict with method names on Worksheet. To prevent this conflict, VSTO renames these events ActivateEvent and SelectEvent.

There are also some new events, such as the Startup and Shutdown events, raised on VSTO project host items such as Workbook, Worksheet, and ChartSheet. ListObject also has several new events that are raised when a ListObject is data bound.

Категории