Host Controls

Several host controls can be added to the worksheet: Chart, ListObject, NamedRange, and XMLMappedRange. Each of these host controls has an underlying Interop object, but these host controls differ from the Interop object because they expose events and have data binding capabilities.

You may be wondering why you would want to use host controls in your Excel solutions and what advantages you gain by using a host control instead of the underlying Interop object. The most obvious benefit is that you can access these objects directly, without traversing the Office object model. This is because these objects are available in your code as first-class .NET objects. Additionally, binding data to an element in your worksheet, such as a cell, is now extremely easy; you use a NamedRange control on the worksheet cell and then bind the data to the NamedRange control. You can also program against events of the host controls. In most cases, the underlying Excel Interop object does not expose any events or has only a limited number of them. Using VSTO, you can now easily respond to users as they move to different areas within a worksheet.

In the next section, you will learn how to add host controls to the worksheet at design time and run time, how to bind data to the host control, and how to cache data in your document for offline use when you are not connected to the network.

0 0

Post a comment